public SimpleEchoCanceller(AudioFormat format, TimeSpan tsDurationSave) { AudioFormat = format; IncomingSamples = format.CalculateNumberOfSamplesForDuration(tsDurationSave); IncomingData = new short[IncomingSamples]; IncomingDataTemp = new short[IncomingSamples]; }
public virtual MediaSample Resample(MediaSample sample, AudioFormat outformat) { if ((sample.AudioFormat.AudioSamplingRate == AudioSamplingRate.sr16000) && (outformat.AudioSamplingRate == AudioSamplingRate.sr8000)) { /// Downsample the data /// short[] sData = Utils.Resample16000To8000(sample.GetShortData()); return new MediaSample(sData, outformat); } else if ((sample.AudioFormat.AudioSamplingRate == AudioSamplingRate.sr16000) && (outformat.AudioSamplingRate == AudioSamplingRate.sr8000)) { /// Upsample the data. This shouldn't happen because our incoming data should always be higher or equal quality /// short[] sData = Utils.Resample8000To16000(sample.GetShortData()); return new MediaSample(sData, outformat); } return sample; }
public BufferFilter(AudioFormat format) { AudioFormat = format; }
public MediaSample PullSample(AudioFormat format, TimeSpan tsDuration) { int nSamples = this.AudioFormat.CalculateNumberOfSamplesForDuration(tsDuration); MediaSample RetSample = new MediaSample(nSamples, this.AudioFormat); if (MinimumSamples != -1) // See if we have enough min samples to send { if ((QueueBuffer.Size / AudioFormat.BytesPerSample) < MinimumSamples) return RetSample; } byte[] bData = QueueBuffer.GetNSamples(RetSample.ByteLength); RetSample.Data = bData; return RetSample; }
public MediaSample(int nNumberSamples, AudioFormat format) { MediaType = MediaType.Audio; m_objAudioFormt = format; Data = new byte[nNumberSamples * BytesPerSample]; }
public MediaSample(short[] sData, AudioFormat format) { MediaType = MediaType.Audio; m_objAudioFormt = format; m_bData = Utils.ConvertShortArrayToByteArray(sData); }
public MediaSample(TimeSpan tsduration, AudioFormat format) { MediaType = MediaType.Audio; m_objAudioFormt = format; m_bData = new byte[m_objAudioFormt.CalculateNumberOfSamplesForDuration(tsduration) * BytesPerSample]; }
public MediaSample(MediaSample refsam, bool bShareData) { MediaType = refsam.MediaType; m_objAudioFormt = new AudioFormat(refsam.AudioFormat.AudioSamplingRate, refsam.AudioFormat.AudioBitsPerSample, refsam.AudioFormat.AudioChannels); if (bShareData == true) m_bData = refsam.Data; else { if (refsam.Data != null) { m_bData = new byte[refsam.Data.Length]; Array.Copy(refsam.Data, m_bData, m_bData.Length); } } }
public MediaSample(byte[] bData, AudioFormat format) { MediaType = MediaType.Audio; m_objAudioFormt = format; m_bData = bData; }
public AudioConferenceMixer(AudioFormat format) { AudioFormat = format; }
public MediaSample PullSample(AudioFormat format, TimeSpan tsDuration) { if (AudioCodec == null) return null; int nSamples = AudioCodec.AudioFormat.CalculateNumberOfSamplesForDuration(tsDuration); int nBytesNeeded = nSamples * AudioCodec.AudioFormat.BytesPerSample; /// Greater than 4 samples in our buffer, remove some if (ReceiveAudioQueue.Size > nBytesNeeded * AudioCodec.AudioFormat.BytesPerSample) ReceiveAudioQueue.GetNSamples(ReceiveAudioQueue.Size - nBytesNeeded*2); if (ReceiveAudioQueue.Size >= nBytesNeeded) { byte [] bAudioData = ReceiveAudioQueue.GetNSamples(nBytesNeeded); /// Incoming RTP packets' audio data is in the codecs native format, we may need to resample for our host (Our windows muxer always expects 16x16, so ulaw must be resampled) MediaSample currentsample = new MediaSample(bAudioData, AudioCodec.AudioFormat); MediaSample newsample = RecvResampler.Resample(currentsample, format); return newsample; } return null; }
public MediaSample PullSample(AudioFormat format, TimeSpan tsDuration) { short[] sPayload = BuildTonePayload(format, tsDuration); return new MediaSample(sPayload, AudioFormat.SixteenBySixteenThousandMono); }
short[] BuildTonePayload(AudioFormat format, TimeSpan tsDuration) { int nSamples = format.CalculateNumberOfSamplesForDuration(tsDuration); short[] sPayload = new short[nSamples]; /// 320 samples for 20 ms packets if (w1 == w2) { double fAmplitude = Utils.SampleFromDb(short.MaxValue, m_fDecibels); for (int i = 0; i < nSamples; i++) { double t = (i + nSequence) / 16000.0f; sPayload[i] = (short)(fAmplitude * (Math.Sin(w1 * t))); } } else { double fAmplitude = Utils.SampleFromDbDualFrequency(short.MaxValue, m_fDecibels); for (int i = 0; i < nSamples; i++) { double t = (i + nSequence) / 16000.0f; sPayload[i] = (short)(fAmplitude * (Math.Sin(w1 * t) + Math.Sin(w2 * t))); } } nSequence += nSamples; return sPayload; }