Esempio n. 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;
   
}
Esempio n. 2
0
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;
}