예제 #1
0
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;
   
}
예제 #2
0
///
/// オーディオリソース生成
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;
}
예제 #3
0
///
/// オーディオリソース生成
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;
}
예제 #4
0
///
/// バッファ構築
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());

}
예제 #5
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
void Wav_set3dDopplerFactor(void * aClassPtr, float aDopplerFactor)
{
	Wav * cl = (Wav *)aClassPtr;
	cl->set3dDopplerFactor(aDopplerFactor);
}
예제 #6
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
void Wav_set3dAttenuation(void * aClassPtr, unsigned int aAttenuationModel, float aAttenuationRolloffFactor)
{
	Wav * cl = (Wav *)aClassPtr;
	cl->set3dAttenuation(aAttenuationModel, aAttenuationRolloffFactor);
}
예제 #7
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
void Wav_stop(void * aClassPtr)
{
	Wav * cl = (Wav *)aClassPtr;
	cl->stop();
}
예제 #8
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
void Wav_setInaudibleBehavior(void * aClassPtr, int aMustTick, int aKill)
{
	Wav * cl = (Wav *)aClassPtr;
	cl->setInaudibleBehavior(!!aMustTick, !!aKill);
}
예제 #9
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
void Wav_set3dColliderEx(void * aClassPtr, AudioCollider * aCollider, int aUserData)
{
	Wav * cl = (Wav *)aClassPtr;
	cl->set3dCollider(aCollider, aUserData);
}
예제 #10
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
void Wav_set3dDistanceDelay(void * aClassPtr, int aDistanceDelay)
{
	Wav * cl = (Wav *)aClassPtr;
	cl->set3dDistanceDelay(!!aDistanceDelay);
}
예제 #11
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
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);
}
예제 #12
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
int Wav_loadMem(void * aClassPtr, unsigned char * aMem, unsigned int aLength)
{
	Wav * cl = (Wav *)aClassPtr;
	return cl->loadMem(aMem, aLength);
}
예제 #13
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
int Wav_load(void * aClassPtr, const char * aFilename)
{
	Wav * cl = (Wav *)aClassPtr;
	return cl->load(aFilename);
}
예제 #14
0
파일: g_wav.cpp 프로젝트: tenso/subphonic
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;
}
예제 #15
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
void Wav_set3dProcessing(void * aClassPtr, int aDo3dProcessing)
{
	Wav * cl = (Wav *)aClassPtr;
	cl->set3dProcessing(!!aDo3dProcessing);
}
예제 #16
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
void Wav_set3dListenerRelative(void * aClassPtr, int aListenerRelative)
{
	Wav * cl = (Wav *)aClassPtr;
	cl->set3dListenerRelative(!!aListenerRelative);
}
예제 #17
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
int Wav_loadFile(void * aClassPtr, File * aFile)
{
	Wav * cl = (Wav *)aClassPtr;
	return cl->loadFile(aFile);
}
예제 #18
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
void Wav_set3dCollider(void * aClassPtr, AudioCollider * aCollider)
{
	Wav * cl = (Wav *)aClassPtr;
	cl->set3dCollider(aCollider);
}
예제 #19
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
double Wav_getLength(void * aClassPtr)
{
	Wav * cl = (Wav *)aClassPtr;
	return cl->getLength();
}
예제 #20
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
void Wav_set3dAttenuator(void * aClassPtr, AudioAttenuator * aAttenuator)
{
	Wav * cl = (Wav *)aClassPtr;
	cl->set3dAttenuator(aAttenuator);
}
예제 #21
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
void Wav_setVolume(void * aClassPtr, float aVolume)
{
	Wav * cl = (Wav *)aClassPtr;
	cl->setVolume(aVolume);
}
예제 #22
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
void Wav_setFilter(void * aClassPtr, unsigned int aFilterId, Filter * aFilter)
{
	Wav * cl = (Wav *)aClassPtr;
	cl->setFilter(aFilterId, aFilter);
}
예제 #23
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
void Wav_setLooping(void * aClassPtr, int aLoop)
{
	Wav * cl = (Wav *)aClassPtr;
	cl->setLooping(!!aLoop);
}
예제 #24
0
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";
      }
    }

}
예제 #25
0
파일: soloud_c.cpp 프로젝트: Itaros/soloud
void Wav_set3dMinMaxDistance(void * aClassPtr, float aMinDistance, float aMaxDistance)
{
	Wav * cl = (Wav *)aClassPtr;
	cl->set3dMinMaxDistance(aMinDistance, aMaxDistance);
}