bool CAudioGenerateDoc::GenerateBegin() { // // Waveform storage // m_waveformBuffer.Start(NumChannels(), SampleRate()); if(m_fileoutput) { if(!OpenGenerateFile(m_wave)) return false; } ProgressBegin(this); if(m_audiooutput) { m_soundstream.SetChannels(NumChannels()); m_soundstream.SetSampleRate(int(SampleRate())); m_soundstream.Open(((CAudioProcessApp *)AfxGetApp())->DirSound()); } return true; }
double AudioNodeStream::DestinationTimeFromTicks(AudioNodeStream* aDestination, TrackTicks aPosition) { MOZ_ASSERT(SampleRate() == aDestination->SampleRate()); StreamTime sourceTime = TicksToTimeRoundDown(SampleRate(), aPosition); GraphTime graphTime = StreamTimeToGraphTime(sourceTime); StreamTime destinationTime = aDestination->GraphTimeToStreamTimeOptimistic(graphTime); return MediaTimeToSeconds(destinationTime); }
void AudioIO::ProcessAudio() { if (!m_RefCount) return; if (m_RealMode == 0) { m_RealMode=2; Reset(); } if ((SampleCount() != OUTPUTCLIENT::Get()->SampleCount()) || (SampleRate() != OUTPUTCLIENT::Get()->SampleRate())) { ChangeBufferAndSampleRate(OUTPUTCLIENT::Get()->SampleCount(), OUTPUTCLIENT::Get()->SampleRate(), m_Parent); } // Only Play() once per set of plugins m_NoExecuted--; if (m_NoExecuted<=0) { if (m_RealMode==1 || m_RealMode==3) OUTPUTCLIENT::Get()->Read(); if (m_RealMode==2 || m_RealMode==3) OUTPUTCLIENT::Get()->Play(); m_NoExecuted=m_RefCount; } }
void LFO::Process(UnsignedType SampleCount) { UnsignedType type = m_Type->Value(); FloatType freq =m_Freq->Value(); FloatType Incr, CyclePos, Pos; CyclePos = StateValue(m_CyclePosInd)->AsFloat; for (UnsignedType n=0; n<SampleCount; n++) { Incr = freq * (DEFAULT_TABLE_LEN / (FloatType)SampleRate()); // Raw Output CyclePos = AdjustPos (CyclePos + Incr); SetOutput (output[0], n, (*ClassObject()->Table(type))[CyclePos]); // 'Cosine' Output Pos = AdjustPos (CyclePos + (DEFAULT_TABLE_LEN * 0.25f)); SetOutput (output[1], n, (*ClassObject()->Table(type))[Pos]); // Inverted Output Pos = AdjustPos (DEFAULT_TABLE_LEN - CyclePos); SetOutput (output[2], n, (*ClassObject()->Table(type))[Pos]); } }
void ResonatorNote::Attack(const MusicDeviceNoteParams &inParams) { ResonatorInstrumentBase* synth = (ResonatorInstrumentBase*) GetAudioUnit(); synth->res = (int)synth->Globals()->GetParameter(kResonatorParam_Resolution); synth->mat = (int)synth->Globals()->GetParameter(kResonatorParam_Material); synth->noteHit = (abs((int) inParams.mPitch - LOW_KEY))%synth->numThump; #ifdef DEBUG_PRINT printf("pitch: %d noteHit: %ld\n,",(int) inParams.mPitch,synth->noteHit); printf("computing with res: %ld using material: %ld\n",synth->res,synth->mat); #endif resonator->SetEigenData(synth->eigendata[synth->res*synth->numRes + synth->mat]); // cbnote all of the inaudible ones removed resonator->SetSampleRate(SampleRate()); resonator->SetRenderParameters( (int) synth->Globals()->GetParameter (kResonatorParam_NumberModes), synth->Globals()->GetParameter(kResonatorParam_DeltaFreqScale), synth->Globals()->GetParameter (kResonatorParam_DeltaAlpha1), synth->Globals()->GetParameter (kResonatorParam_DeltaAlpha2), synth->Globals()->GetParameter(kResonatorParam_DeltaSoundScale) ); resonator->Thump(inParams.mVelocity/128.0, synth->thumpers[synth->noteHit], synth->Globals()->GetParameter (kResonatorParam_ThumpBase)); // resonator only needs to know where SendNoteNotification (kAudioUnitEvent_BeginParameterChangeGesture, kParam_NoteOnEvent); }
SampleRate SampleRate::KiloHertz(uint32 kSamplesPerSecond) { //check the parameter is within the nanoseconds range assert(kSamplesPerSecond <= TimeSpan::NANOSECONDS_PER_SECOND / 1000); //build a sample rate from hertz and the 1000's samples per second return SampleRate(rateType_hertz, kSamplesPerSecond * 1000); }
SampleRate SampleRate::Hertz(uint32 samplesPerSecond) { //check the parameter is within the nanoseconds range assert(samplesPerSecond <= TimeSpan::NANOSECONDS_PER_SECOND); //build a sample rate from hertz and the samples per second return SampleRate(rateType_hertz, samplesPerSecond); }
BasicWaveFormCache* AudioContext::GetBasicWaveFormCache() { MOZ_ASSERT(NS_IsMainThread()); if (!mBasicWaveFormCache) { mBasicWaveFormCache = new BasicWaveFormCache(SampleRate()); } return mBasicWaveFormCache; }
double AudioNodeStream::DestinationTimeFromTicks(AudioNodeStream* aDestination, StreamTime aPosition) { MOZ_ASSERT(SampleRate() == aDestination->SampleRate()); GraphTime graphTime = StreamTimeToGraphTime(aPosition); StreamTime destinationTime = aDestination->GraphTimeToStreamTimeOptimistic(graphTime); return StreamTimeToSeconds(destinationTime); }
double AudioNodeStream::FractionalTicksFromDestinationTime(AudioNodeStream* aDestination, double aSeconds) { MOZ_ASSERT(aDestination->SampleRate() == SampleRate()); MOZ_ASSERT(SampleRate() == GraphRate()); double destinationSeconds = std::max(0.0, aSeconds); double destinationFractionalTicks = destinationSeconds * SampleRate(); MOZ_ASSERT(destinationFractionalTicks < STREAM_TIME_MAX); StreamTime destinationStreamTime = destinationFractionalTicks; // round down // MediaTime does not have the resolution of double double offset = destinationFractionalTicks - destinationStreamTime; GraphTime graphTime = aDestination->StreamTimeToGraphTime(destinationStreamTime); StreamTime thisStreamTime = GraphTimeToStreamTimeOptimistic(graphTime); double thisFractionalTicks = thisStreamTime + offset; MOZ_ASSERT(thisFractionalTicks >= 0.0); return thisFractionalTicks; }
TrackTicks AudioNodeStream::TicksFromDestinationTime(MediaStream* aDestination, double aSeconds) { AudioNodeStream* destination = aDestination->AsAudioNodeStream(); MOZ_ASSERT(destination); double thisSeconds = TimeFromDestinationTime(destination, aSeconds); // Round to nearest TrackTicks ticks = thisSeconds * SampleRate() + 0.5; return ticks; }
virtual void Attack(const MusicDeviceNoteParams &inParams) { #if DEBUG_PRINT printf("TestNote::Attack %08X %d\n", this, GetState()); #endif double sampleRate = SampleRate(); phase = 0.; amp = 0.; maxamp = 0.4 * pow(inParams.mVelocity/127., 3.); up_slope = maxamp / (0.1 * sampleRate); dn_slope = -maxamp / (0.9 * sampleRate); fast_dn_slope = -maxamp / (0.005 * sampleRate); }
void MinstrelWifiManager::CheckInit (MinstrelWifiRemoteStation *station) { if (!station->m_initialized && GetNSupported (station) > 1) { // Note: we appear to be doing late initialization of the table // to make sure that the set of supported rates has been initialized // before we perform our own initialization. m_nsupported = GetNSupported (station); m_minstrelTable = MinstrelRate (m_nsupported); m_sampleTable = SampleRate (m_nsupported, std::vector<uint32_t> (m_sampleCol)); InitSampleTable (station); RateInit (station); station->m_initialized = true; } }
double AudioNodeStream::TimeFromDestinationTime(AudioNodeStream* aDestination, double aSeconds) { MOZ_ASSERT(aDestination->SampleRate() == SampleRate()); double destinationSeconds = std::max(0.0, aSeconds); StreamTime streamTime = SecondsToMediaTime(destinationSeconds); // MediaTime does not have the resolution of double double offset = destinationSeconds - MediaTimeToSeconds(streamTime); GraphTime graphTime = aDestination->StreamTimeToGraphTime(streamTime); StreamTime thisStreamTime = GraphTimeToStreamTimeOptimistic(graphTime); double thisSeconds = MediaTimeToSeconds(thisStreamTime) + offset; MOZ_ASSERT(thisSeconds >= 0.0); return thisSeconds; }
static unsigned FrameLength(FrameHeader fh) { unsigned bitrate = BitRate(fh); if (!bitrate) return 0; unsigned samplerate = SampleRate(fh); if (!samplerate) return 0; if (fh.s.layer == 3) return (((12*bitrate) / samplerate) + fh.s.padding) * 4; unsigned samples = 1152; if ((fh.s.version == 0 || fh.s.version == 2) && fh.s.layer == 1) samples = 576; return (samples*bitrate)/(8*samplerate) + fh.s.padding; }
MediaPacket::MediaPacket(IN const AVStream& _avStream, IN const AVPacket* _pAvPacket) { // save codec pointer pAvCodecPar_ = _avStream.codecpar; enum AVMediaType stream = pAvCodecPar_->codec_type; if (stream != AVMEDIA_TYPE_AUDIO && stream != AVMEDIA_TYPE_VIDEO) { stream = AVMEDIA_TYPE_DATA; } SetStreamType(stream); SetCodec(pAvCodecPar_->codec_id); Width(pAvCodecPar_->width); Height(pAvCodecPar_->height); SampleRate(pAvCodecPar_->sample_rate); Channels(pAvCodecPar_->channels); // copy packet pAvPacket_ = const_cast<AVPacket*>(_pAvPacket); }
/** * - Sets up the channel order array (1 channel) * - Sets channel count to use 1 analog channel * - Sets up 'connection' to use the DI-194RS settings * - Creates the following lists: * - m_ADChannelList\n * Normal order * - m_ADMethodList\n * IOS Average * - Disables the digital channel * - Calls sample rate function passing it the default sample rate, * as defined in the dsdk */ di194_dsdk::di194_dsdk():dsdk() { chan_order[0] = 0; m_ADChannelCount = 1; // create new lists m_ADChannelList = new int[m_ADChannelCount]; m_ADMethodList = new int[m_ADChannelCount]; for(int i=0; i<m_ADChannelCount; i++) { m_ADChannelList[i] = i; m_ADMethodList[i] = IOS_AVERAGE; chan_order[i] = i * DI194_CHAN_SIZE; } digital_chan = false; m_MaxBurstRate = 240.00; // set to default sample rate based on channels activated SampleRate(m_SampleRate); }
bool HSNote::Attack(const MusicDeviceNoteParams &inParams) { HSPad* hsp = (HSPad*) GetAudioUnit(); wavetable = hsp->getWavetable(); float freq = Frequency()*(1-GetGlobalParameter(kParameter_TouchSensitivity)*pow(inParams.mVelocity/127., 2.)); wavetable_idx = wavetable->closestMatchingWavetable(freq); wavetable_num_samples = wavetable->getNumSamples(); wavetable_sample_rate = wavetable->getSampleRate(); double sampleRate = SampleRate(); phase = (rand()/(RAND_MAX+1.0))*wavetable_num_samples; amp = 0.; maxamp = 0.4 * pow(inParams.mVelocity/127., 2.); float at = GetGlobalParameter(kParameter_AttackTime); // If at is 0, we set up_slope to maxamp/50. That is big enough to start the note // seemingly immediately, yet avoiding an ugly chipping sound that comes if you set // it to maxamp. up_slope = maxamp / (at==0.0?50.0:(at/1000.0 * sampleRate)); float rt = GetGlobalParameter(kParameter_ReleaseTime); if (rt == 0) { // This is not 0, because that makes an ugly chipping sound when the note // is released. 0.99 is small enough to stop the note seemingly immediately dn_slope = 0.99; } else { double num_frames = rt/1000.0 * sampleRate; double off_threshold = 0.01; // 20dB dn_slope = pow(off_threshold, (double)1.0/num_frames); } fast_dn_slope = -maxamp / (0.005 * sampleRate); return true; }
float AudioOutputDevice::latency() { return float(MaxSamplesPerCycle()) / float(SampleRate()); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // HSPad::Render //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ OSStatus HSNote::Render(UInt64 inAbsoluteSampleFrame, UInt32 inNumFrames, AudioBufferList** inBufferList, UInt32 inOutBusCount) { // TestNote only writes into the first bus regardless of what is handed to us. const int bus0 = 0; AudioBufferList* inBuffer = inBufferList[bus0]; int numChans = inBuffer->mNumberBuffers; if (numChans > 2) return -1; float volumeFactor = pow(10, GetGlobalParameter(kParameter_Volume)/10); float *left, *right; wavetable->lockWavetables(); { float *wt = wavetable->getWavetableData(wavetable_idx); float base_frequency = wavetable->getBaseFrequency(wavetable_idx); left = (float*)inBuffer->mBuffers[0].mData; right = numChans == 2 ? (float*)inBuffer->mBuffers[1].mData : 0; double freq = Frequency()/base_frequency*((double)wavetable_sample_rate)/SampleRate(); switch (GetState()) { case kNoteState_Attacked : case kNoteState_Sostenutoed : case kNoteState_ReleasedButSostenutoed : case kNoteState_ReleasedButSustained : { for (UInt32 frame=0; frame<inNumFrames; ++frame) { if (amp < maxamp) amp += up_slope; int pint = (int) phase; float out1 = wt[pint%wavetable_num_samples]; float out2 = wt[(pint+1)%wavetable_num_samples]; float out = ((1-(phase-pint))*out1+(phase-pint)*out2) * amp * volumeFactor; phase += freq; if (phase >= wavetable_num_samples) phase -= wavetable_num_samples; left[frame] += out; if (right) right[frame] += out; } } break; case kNoteState_Released : { UInt32 endFrame = 0xFFFFFFFF; for (UInt32 frame=0; frame<inNumFrames; ++frame) { if (amp > 0.0) amp *= dn_slope; else if (endFrame == 0xFFFFFFFF) endFrame = frame; int pint = (int) phase; float out1 = wt[pint%wavetable_num_samples]; float out2 = wt[(pint+1)%wavetable_num_samples]; float out = ((1-(phase-pint))*out1+(phase-pint)*out2) * amp * volumeFactor; phase += freq; if (phase >= wavetable_num_samples) phase -= wavetable_num_samples; left[frame] += out; if (right) right[frame] += out; } if (endFrame != 0xFFFFFFFF) NoteEnded(endFrame); } break; case kNoteState_FastReleased : { UInt32 endFrame = 0xFFFFFFFF; for (UInt32 frame=0; frame<inNumFrames; ++frame) { if (amp > 0.0) amp += fast_dn_slope; else if (endFrame == 0xFFFFFFFF) endFrame = frame; int pint = (int) phase; float out1 = wt[pint%wavetable_num_samples]; float out2 = wt[(pint+1)%wavetable_num_samples]; float out = ((1-(phase-pint))*out1+(phase-pint)*out2) * amp * volumeFactor; phase += freq; if (phase >= wavetable_num_samples) phase -= wavetable_num_samples; left[frame] += out; if (right) right[frame] += out; } if (endFrame != 0xFFFFFFFF) NoteEnded(endFrame); } break; default : break; } } wavetable->unlockWavetables(); return noErr; }
OSStatus TestNote::Render(UInt64 inAbsoluteSampleFrame, UInt32 inNumFrames, AudioBufferList** inBufferList, UInt32 inOutBusCount) { float *left, *right; /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Changes to this parameter (kGlobalVolumeParam) are not being de-zippered; Left as an exercise for the reader ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */ float globalVol = GetGlobalParameter(kGlobalVolumeParam); // TestNote only writes into the first bus regardless of what is handed to us. const int bus0 = 0; int numChans = inBufferList[bus0]->mNumberBuffers; if (numChans > 2) return -1; left = (float*)inBufferList[bus0]->mBuffers[0].mData; right = numChans == 2 ? (float*)inBufferList[bus0]->mBuffers[1].mData : 0; double sampleRate = SampleRate(); double freq = Frequency() * (twopi/sampleRate); #if DEBUG_PRINT_RENDER printf("TestNote::Render %p %d %g %g\n", this, GetState(), phase, amp); #endif switch (GetState()) { case kNoteState_Attacked : case kNoteState_Sostenutoed : case kNoteState_ReleasedButSostenutoed : case kNoteState_ReleasedButSustained : { for (UInt32 frame=0; frame<inNumFrames; ++frame) { if (amp < maxamp) amp += up_slope; float out = pow5(sin(phase)) * amp * globalVol; phase += freq; if (phase > twopi) phase -= twopi; left[frame] += out; if (right) right[frame] += out; } } break; case kNoteState_Released : { UInt32 endFrame = 0xFFFFFFFF; for (UInt32 frame=0; frame<inNumFrames; ++frame) { if (amp > 0.0) amp += dn_slope; else if (endFrame == 0xFFFFFFFF) endFrame = frame; float out = pow5(sin(phase)) * amp * globalVol; phase += freq; left[frame] += out; if (right) right[frame] += out; } if (endFrame != 0xFFFFFFFF) { #if DEBUG_PRINT printf("TestNote::NoteEnded %p %d %g %g\n", this, GetState(), phase, amp); #endif NoteEnded(endFrame); } } break; case kNoteState_FastReleased : { UInt32 endFrame = 0xFFFFFFFF; for (UInt32 frame=0; frame<inNumFrames; ++frame) { if (amp > 0.0) amp += fast_dn_slope; else if (endFrame == 0xFFFFFFFF) endFrame = frame; float out = pow5(sin(phase)) * amp * globalVol; phase += freq; left[frame] += out; if (right) right[frame] += out; } if (endFrame != 0xFFFFFFFF) { #if DEBUG_PRINT printf("TestNote::NoteEnded %p %d %g %g\n", this, GetState(), phase, amp); #endif NoteEnded(endFrame); } } break; default : break; } return noErr; }
SampleRate SampleRate::Event() { return SampleRate(rateType_event, 0); }
SampleRate SampleRate::Seconds(uint32 secondsBetweenSamples) { //build a sample rate from seconds and the seconds between samples return SampleRate(rateType_seconds, secondsBetweenSamples); }
/** * Overall number of channels to scan. All digital ports count as one * channel here. The digital ports are all either acquiring or not, together. * Sets default values for anything affected by changing the number of * channels being scanned. * - Lists: * - m_ADChannelList\n * Normal order. * - m_ADMethodList\n * IOS Average for analog, IOS Last Point for digital. * - chan_order\n * Normal order. * - If all channels are requested, changes last one to digital. * - Calls SampleRate() function with current value. Allows it to be checked. * - Tells device what channels to scan. * * Error Codes set:\n * EBUSY = Acquiring.\n * ENOLINK = Device not connected.\n * EBOUNDS = Parameter out of bounds.\n * Errors set by Dcmd().\n * Errors set by Ccmd(). * * @pre Not acquiring.\n * Connected.\n * Bounds between 1 and DI194_CHANNELS * @param ChannelCount Number of channels to scan. */ void di194_dsdk::ADChannelCount(const int ChannelCount) { // can't set while acquiring data if(m_acquiring_data) { m_last_error = EBUSY; return; } // must be connected if(!m_connection.is_comm_open()) { m_last_error = ENOLINK; return; } // bounds check if(ChannelCount > DI194_CHANNELS || ChannelCount < 1) { m_last_error = EBOUNDS; return; } // pointer check if(m_ADChannelList != 0) { delete [] m_ADChannelList; m_ADChannelList = 0; } // pointer check if(m_ADMethodList != 0) { delete [] m_ADMethodList; m_ADMethodList = 0; } m_ADChannelCount = ChannelCount; m_ADChannelList = new int[m_ADChannelCount]; m_ADMethodList = new int[m_ADChannelCount]; // initialize with default values for(int i=0; i<m_ADChannelCount; i++) { m_ADChannelList[i] = i; m_ADMethodList[i] = IOS_AVERAGE; } // check if all channels requested // if so, change last channel to digital if(m_ADChannelCount == DI194_CHANNELS) { m_ADChannelList[DI194_CHANNELS-1] = -1; // 'all channels' includes digital ports digital_chan = true; // last point makes more sense for digital m_ADMethodList[DI194_CHANNELS-1] = IOS_LAST_POINT; // setup channel order (used in conversion) for(int i=0; i<DI194_CHANNELS-1; i++) chan_order[i] = i; } else // no digital { digital_chan = false; for(int i=0; i<m_ADChannelCount; i++) chan_order[i] = i; } // set sample rate according to new channels SampleRate(m_SampleRate); /* set channels to scan for acquisition 1 - analog channel 1 2 - analog channel 2 4 - analog channel 3 8 - analog channel 4 add together to get any combination of channels OR each bit is a channel: 4 (left) to 1 (right) using above scheme channel 1, binary: 0001 (decimal: 1) channel 2,3 binary: 0110 (decimal: 6) */ u_int8_t chan = 0; for(int i=0; i<m_ADChannelCount; i++) { if(m_ADChannelList[i] > -1) chan |= (0x01 << m_ADChannelList[i]); } // enable digital channel input if(digital_chan) { if(!Dcmd(m_connection, 1)) { m_last_error = my_errno; return; } } else // disable digital channel input { if(!Dcmd(m_connection, 0)) { m_last_error = my_errno; return; } } // enable analog channels if(!Ccmd(m_connection, chan)) { m_last_error = my_errno; return; } }