<commit_before>﻿/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/

#include "stdafx.h"

#include <sndfile.h>

#include "audio.h"
#include "Globals.h"
#include "McZapkie/mctools.h"
#include "Logs.h"
#include "ResourceManager.h"
#include "usefull.h"

namespace audio {

openal_buffer::openal_buffer( std::string const &Filename ) :
    name( Filename ) {

	SF_INFO si;
	si.format = 0;

	std::string file = Filename;
	std::replace(file.begin(), file.end(), '\\', '/');

	SNDFILE *sf = sf_open(file.c_str(), SFM_READ, &si);

	if (sf == nullptr)
		throw std::runtime_error("sound: sf_open failed");

	sf_command(sf, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE);

	int16_t *fbuf = new int16_t[si.frames * si.channels];
	if (sf_readf_short(sf, fbuf, si.frames) != si.frames)
		throw std::runtime_error("sound: incomplete file");

	sf_close(sf);

	rate = si.samplerate;

	int16_t *buf = nullptr;
	if (si.channels == 1)
		buf = fbuf;
	else
	{
		WriteLog("sound: warning: mixing multichannel file to mono");
		buf = new int16_t[si.frames];
		for (size_t i = 0; i < si.frames; i++)
		{
			int32_t accum = 0;
			for (size_t j = 0; j < si.channels; j++)
				accum += fbuf[i * si.channels + j];
			buf[i] = accum / si.channels;
		}<commit_msg>log sound files<commit_after>﻿/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/

#include "stdafx.h"

#include <sndfile.h>

#include "audio.h"
#include "Globals.h"
#include "McZapkie/mctools.h"
#include "Logs.h"
#include "ResourceManager.h"
#include "usefull.h"

namespace audio {

openal_buffer::openal_buffer( std::string const &Filename ) :
    name( Filename ) {

	SF_INFO si;
	si.format = 0;

	std::string file = Filename;
	std::replace(file.begin(), file.end(), '\\', '/');

	WriteLog("sound: loading file: " + file);

	SNDFILE *sf = sf_open(file.c_str(), SFM_READ, &si);

	if (sf == nullptr)
		throw std::runtime_error("sound: sf_open failed");

	sf_command(sf, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE);

	int16_t *fbuf = new int16_t[si.frames * si.channels];
	if (sf_readf_short(sf, fbuf, si.frames) != si.frames)
		throw std::runtime_error("sound: incomplete file");

	sf_close(sf);

	rate = si.samplerate;

	int16_t *buf = nullptr;
	if (si.channels == 1)
		buf = fbuf;
	else
	{
		WriteLog("sound: warning: mixing multichannel file to mono");
		buf = new int16_t[si.frames];
		for (size_t i = 0; i < si.frames; i++)
		{
			int32_t accum = 0;
			for (size_t j = 0; j < si.channels; j++)
				accum += fbuf[i * si.channels + j];
			buf[i] = accum / si.channels;
		}
{'fraction_non_alphanumeric': 0.15703069236259815, 'fraction_numerical': 0.013561741613133477, 'mean_word_length': 3.9261862917398944, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5464375', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1089, 'n_words': 294}