bool ProgramState::dumpToFile() { if(!runningDump()) { DERROR("not running dump"); return false; } Wav w; w.make(wavdump->getBytes(),dumpoff*2 /*bytes*/,getSampleRate(),nchan,16); string fname = running_dump_name; DASSERT(fname.size()>0); w.save(fname,true); cout << "wrote: " << fname.c_str() << endl; w.del(); delete wavdump; wavdump=NULL; dumplen=0; return true; }
/// /// オーディオリソース生成 AudioResourcePtr AudioResource::create( const t3::File& file ///< ファイル ) { // とりあえず.wavだけサポート Wav wav; wav.setup(file); // リソース生成 AudioResourcePtr res; res.reset(T3_SYS_NEW AudioResource); res->resourceName(file.name().c_str()); res->setupBuffer(wav); res->createHandle(); return res; }
/// /// オーディオリソース生成 AudioResourcePtr AudioResource::create( FilePath& filepath ///< ファイルパス ) { // 未サポート判定 T3_ASSERT_MSG(filepath.ext() == ".wav", "%s is not support. only supported .wav", filepath.filename().c_str()); // とりあえず.wavだけサポート Wav wav; wav.load(filepath); // リソース生成 AudioResourcePtr res; res.reset(T3_SYS_NEW AudioResource); res->setupBuffer(wav); res->resourceName(filepath.filename().c_str()); res->createHandle(); return res; }
/// /// バッファ構築 void AudioResource::setupBuffer( const Wav& wav ///< 元となるサウンドデータ ) { // オーディオフォーマット調査 cross::AudioSystem::AudioFormat format; if (wav.channel() == 1) { // モノラル if (wav.bitPerSample() == 8) { format = cross::AudioSystem::AudioFormat::MONO_8; } else { format = cross::AudioSystem::AudioFormat::MONO_16; } } else { // ステレオ if (wav.bitPerSample() == 8) { format = cross::AudioSystem::AudioFormat::STEREO_8; } else { format = cross::AudioSystem::AudioFormat::STEREO_16; } } // バッファ生成 cross::AudioSystem::setBufferData( id_, format, wav.getData(), wav.size(), wav.samplingRate() ); // 生成ログ出力 T3_SYSTEM_LOG("create Wav\n"); T3_SYSTEM_LOG(" channel %d\n", wav.channel()); T3_SYSTEM_LOG(" bit sample %d\n", wav.bitPerSample()); T3_SYSTEM_LOG(" rate %d\n", wav.samplingRate()); T3_SYSTEM_LOG(" size %d\n", wav.size()); }
void Wav_set3dDopplerFactor(void * aClassPtr, float aDopplerFactor) { Wav * cl = (Wav *)aClassPtr; cl->set3dDopplerFactor(aDopplerFactor); }
void Wav_set3dAttenuation(void * aClassPtr, unsigned int aAttenuationModel, float aAttenuationRolloffFactor) { Wav * cl = (Wav *)aClassPtr; cl->set3dAttenuation(aAttenuationModel, aAttenuationRolloffFactor); }
void Wav_stop(void * aClassPtr) { Wav * cl = (Wav *)aClassPtr; cl->stop(); }
void Wav_setInaudibleBehavior(void * aClassPtr, int aMustTick, int aKill) { Wav * cl = (Wav *)aClassPtr; cl->setInaudibleBehavior(!!aMustTick, !!aKill); }
void Wav_set3dColliderEx(void * aClassPtr, AudioCollider * aCollider, int aUserData) { Wav * cl = (Wav *)aClassPtr; cl->set3dCollider(aCollider, aUserData); }
void Wav_set3dDistanceDelay(void * aClassPtr, int aDistanceDelay) { Wav * cl = (Wav *)aClassPtr; cl->set3dDistanceDelay(!!aDistanceDelay); }
int Wav_loadMemEx(void * aClassPtr, unsigned char * aMem, unsigned int aLength, int aCopy, int aTakeOwnership) { Wav * cl = (Wav *)aClassPtr; return cl->loadMem(aMem, aLength, !!aCopy, !!aTakeOwnership); }
int Wav_loadMem(void * aClassPtr, unsigned char * aMem, unsigned int aLength) { Wav * cl = (Wav *)aClassPtr; return cl->loadMem(aMem, aLength); }
int Wav_load(void * aClassPtr, const char * aFilename) { Wav * cl = (Wav *)aClassPtr; return cl->load(aFilename); }
int SampleHold::loadDir(const string& path) { ProgramState& progstate = ProgramState::instance(); if(path.size()==0) { DERROR("path empty"); return 1; } FileDir fd; bool exist = fd.read(path, false, ".wav", false, false); if(!exist) { DERROR("(E) SampleHold loadDIR(): no such dir!"); return 1; } vector<string> files; fd.getFiles(files); if(files.size()==0)return 0; for(unsigned int i=0; i<files.size(); i++) { Wav w; string str=path+files[i]; //FIXME: better errorchecking! Wav::err ret = w.load(str); //w.info(); if(ret==Wav::FILE_NOTFOUND_ERR)continue; //something went wrong but probably file does not exist... if(!w.ok()) { DERROR("something wrong happend"); continue; } WavSample* samp; if(w.isStereo()) { SampleValue* l = new SampleValue(w.makeSample(Wav::EXTRACT_LEFT)); l->setResampleRate(w.getSampleRate(), progstate.getSampleRate()); SampleValue* r = new SampleValue(w.makeSample(Wav::EXTRACT_RIGHT)); r->setResampleRate(w.getSampleRate(), progstate.getSampleRate()); samp = new WavSample(files[i], l,r); } else { SampleValue* m = new SampleValue(w.makeSample(Wav::EXTRACT_ALL)); m->setResampleRate(w.getSampleRate(), progstate.getSampleRate()); samp = new WavSample(files[i], m); } samples.push_back(samp); w.del(); } return 0; }
void Wav_set3dProcessing(void * aClassPtr, int aDo3dProcessing) { Wav * cl = (Wav *)aClassPtr; cl->set3dProcessing(!!aDo3dProcessing); }
void Wav_set3dListenerRelative(void * aClassPtr, int aListenerRelative) { Wav * cl = (Wav *)aClassPtr; cl->set3dListenerRelative(!!aListenerRelative); }
int Wav_loadFile(void * aClassPtr, File * aFile) { Wav * cl = (Wav *)aClassPtr; return cl->loadFile(aFile); }
void Wav_set3dCollider(void * aClassPtr, AudioCollider * aCollider) { Wav * cl = (Wav *)aClassPtr; cl->set3dCollider(aCollider); }
double Wav_getLength(void * aClassPtr) { Wav * cl = (Wav *)aClassPtr; return cl->getLength(); }
void Wav_set3dAttenuator(void * aClassPtr, AudioAttenuator * aAttenuator) { Wav * cl = (Wav *)aClassPtr; cl->set3dAttenuator(aAttenuator); }
void Wav_setVolume(void * aClassPtr, float aVolume) { Wav * cl = (Wav *)aClassPtr; cl->setVolume(aVolume); }
void Wav_setFilter(void * aClassPtr, unsigned int aFilterId, Filter * aFilter) { Wav * cl = (Wav *)aClassPtr; cl->setFilter(aFilterId, aFilter); }
void Wav_setLooping(void * aClassPtr, int aLoop) { Wav * cl = (Wav *)aClassPtr; cl->setLooping(!!aLoop); }
int main(int argc, char* argv[]) { if(argc <= 1) { cout << "Error"; exit(0); } bool waitingForParam = true; string paramName; for (int i = 1; i < argc; ++i) { if (waitingForParam) { if (argv[i][0] == '-') { // new param paramName = argv[i]; waitingForParam = false; } } else { if (argv[i][0] == '-') { // empty value params.insert(make_pair(paramName, string())); paramName = argv[i]; } else { params.insert(make_pair(paramName, string(argv[i]))); waitingForParam = true; } } } string sample_name = argv[1]; Wav sampleWave; MFCC mfcc; if(!sampleWave.readwav(sample_name, DOUBLE)) { cout << "Cannot read the sample file"; exit(0); } vector<double> rawData = sampleWave.returnRawSignal(); int sample_rate = sampleWave.returnSampleRate(); vector<DIMENSIONS_2> MFCC = mfcc.transform(rawData, sample_rate); if(exists("-t", params)) { Training training("repository/training/"); if(training.open()) { struct sampleData sample; sample.N = MFCC.size(); sample.M = MFCC[0].size(); sample.sample_name = argv[3]; sample.speaker = argv[4]; training.write_2D(MFCC, sample); } } if(exists("-r", params)) { Training training("repository/training/"); pair<int, string> minDistance(INT_MAX, ""); if(training.open()) { vector<string> files = training.files(); string person; for(unsigned i=0; (i < files.size()); i++) { vector<vector<double> > data; data.clear(); string* speaker_features = new string[2]; data = training.read_2D("repository/training/" + files[i], speaker_features); int currDistance = DTW::Distance(MFCC, data); if(currDistance < minDistance.first) { minDistance.first = currDistance; minDistance.second = speaker_features[0]; person = speaker_features[1]; } } cout << "You said: " << minDistance.second << " You sound like: " << person << endl; }else{ cout << "Cannot open the training file"; } } }
void Wav_set3dMinMaxDistance(void * aClassPtr, float aMinDistance, float aMaxDistance) { Wav * cl = (Wav *)aClassPtr; cl->set3dMinMaxDistance(aMinDistance, aMaxDistance); }