ErrorType SoundStreamData::Open( StreamReader *streamReader, Int chunkSize) { Unload(); if (!streamReader->IsOpen()) return Error::Throw(kErrorFileNotFound, String("(%s(%p, %d): streamReader->mName=\"%s\"]", FastFunctionName, streamReader, chunkSize, streamReader->GetName().GetCString())); mStreamReader = streamReader; mProperties.SetSampleCount(chunkSize); mStreamReader->SeekTo(0); Char check = mStreamReader->ReadByte(); mStreamReader->SeekTo(0); switch(check) { case '\x4f': return OpenOgg(); case '\x52': return OpenWav(); default: Unload(); return Error::Throw(kErrorSoundFormatInvalid, String("(%s(%p, %d): streamReader->mName=\"%s\"]", FastFunctionName, streamReader, chunkSize, streamReader->GetName().GetCString())); } }
int DecodeMusic(std::string const& filename, DecodedMusic* Sound){ // Opening file FILE* stream = FileFinder::fopenUTF8(filename, "rb"); if (!stream) { Output::Warning("Couldn't open music file %s", filename.c_str()); return -1; } // Trying to use internal decoder audio_decoder = AudioDecoder::Create(stream, filename); if (audio_decoder != NULL) return OpenAudioDecoder(stream, Sound, filename); // Reading and parsing the magic u32 magic; fread(&magic, 4, 1, stream); if (magic == 0x46464952) return OpenWav(stream, Sound); else if (magic == 0x5367674F) return OpenOgg(stream, Sound); else{ fclose(stream); Output::Warning("Unsupported music format (%s)", filename.c_str()); return -1; } }
ErrorType SoundStreamData::Open( const String &fileName, Int chunkSize) { Unload(); mStreamReader = new FileReader(fileName); if (!mStreamReader->IsOpen()) { delete (FileReader*)mStreamReader; mStreamReader = 0; return Error::Throw(kErrorFileNotFound, String("[%s(\"%s\", %d)]", FastFunctionName, fileName.GetCString(), chunkSize)); } mProperties.SetSampleCount(chunkSize); mAllocatedStreamReader = true; Char check = mStreamReader->ReadByte(); mStreamReader->SeekTo(0); switch(check) { case '\x4f': return OpenOgg(); case '\x52': return OpenWav(); default: Unload(); return Error::Throw(kErrorSoundFormatInvalid, String("[%s(\"%s\", %d)]", FastFunctionName, fileName.GetCString(), chunkSize)); } }
/** * @function ARB_Run * @brief start / resume the arbitrary handler * @param arb_st *arb: pointer to the arbitrary waveform handler * @return none */ void ARB_Run(arb_st *arb) { if(arb != NULL) { arb->run = 1; currentArb = arb; /*DDS on*/ AD9834_Resume(0); switch(arb->waveformType) { /*<noise> special case: overwrite frequency with MAX_SAMPLE_PER_SECOND*/ case ARB_WAVE_NOISE: TmrSetCallback(ARB_TIMER, ARB_IsrNoise); TmrSetFrequency(ARB_TIMER, MAX_SAMPLE_PER_SECOND); TmrLaunch(ARB_TIMER); break; /*<wav> special case: timer & ISR are directly handled by OpenWav()*/ case ARB_WAVE_WAV: if(WavGetStatus() == WAV_STOPPED) { OpenWav("waveform.wav"); } WavPlay(arb->pOut); break; /*analog in: special ISR*/ case ARB_WAVE_ANA_IN: TmrSetCallback(ARB_TIMER, ARB_IsrAnaIn); TmrLaunch(ARB_TIMER); break; /*for all other waveforms: just start the timer with the default ISR*/ default: TmrSetCallback(ARB_TIMER, ARB_IsrStd); TmrLaunch(ARB_TIMER); break; } } }