本文整理汇总了C#中IAudioStream类的典型用法代码示例。如果您正苦于以下问题:C# IAudioStream类的具体用法?C# IAudioStream怎么用?C# IAudioStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IAudioStream类属于命名空间,在下文中一共展示了IAudioStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartRecorder
/// <summary>
/// Starts the recorder.
/// </summary>
/// <param name="stream">The stream.</param>
/// <param name="fileStream">The file stream.</param>
/// <param name="sampleRate">The sample rate.</param>
/// <returns>Task<System.Boolean>.</returns>
public async Task<bool> StartRecorder(IAudioStream stream, Stream fileStream, int sampleRate)
{
if (_stream != null || stream == null)
{
return false;
}
_stream = stream;
try
{
_writer = new BinaryWriter(fileStream, Encoding.UTF8);
}
catch (Exception)
{
return false;
}
_byteCount = 0;
_stream.OnBroadcast += OnStreamBroadcast;
var result = await _stream.Start(sampleRate);
if (result)
{
_sampleRate = sampleRate;
_bitsPerSample = stream.BitsPerSample;
_channelCount = stream.ChannelCount;
}
return result;
}
示例2: ColorGenerator
public ColorGenerator(IAudioStream audioStream, int numberOfColors = 3)
: base(audioStream, numberOfColors)
{
if (numberOfColors < 1)
{
throw new ArgumentOutOfRangeException();
}
var lowFreqMaxBucket = this.GetFrequencyBinIndex(LowFrequencyMax);
var lowFreqBucket = new ColorGeneratorBucket(this.GetFrequencyBinIndex(LowFrequencyMin), lowFreqMaxBucket, this.IterationsPerSecond, hueShift: 0);
this.generatorBuckets.Add(lowFreqBucket);
var freqsPerBucket = (this.MaxFrequencyBinIndex - lowFreqMaxBucket) / (numberOfColors - 1);
if (freqsPerBucket < 1)
{
throw new ArgumentOutOfRangeException("Not enough frequency bins for the remaining colors");
}
for (int freqIndex = lowFreqMaxBucket + 1; freqIndex <= this.MaxFrequencyBinIndex - 1; freqIndex += freqsPerBucket)
{
ushort hueShift = (ushort)(ushort.MaxValue / numberOfColors * this.generatorBuckets.Count);
this.generatorBuckets.Add(
new ColorGeneratorBucket(freqIndex, Math.Min(freqIndex + freqsPerBucket - 1, this.MaxFrequencyBinIndex), this.IterationsPerSecond, hueShift: hueShift));
}
}
示例3: StartRecorder
public bool StartRecorder(IAudioStream stream, string fileName)
{
if (this.stream != null || stream == null)
{
return false;
}
this.stream = stream;
try
{
this.streamWriter = new StreamWriter(fileName, false);
this.writer = new BinaryWriter(this.streamWriter.BaseStream, Encoding.UTF8);
}
catch (Exception)
{
return false;
}
this.byteCount = 0;
this.stream.OnBroadcast += OnStreamBroadcast;
this.stream.OnActiveChanged += StreamActiveChanged;
if (!this.stream.Active)
{
this.stream.Start();
}
return true;
}
示例4: StartRecorder
public bool StartRecorder(IAudioStream stream, string fileName)
{
if (this.stream != null || stream == null)
{
return false;
}
this.stream = stream;
try
{
//this.streamWriter = new StreamWriter(fileName, false);
this.writer = new BinaryWriter(this.streamWriter.BaseStream, Encoding.UTF8);
}
catch (Exception)
{
return false;
}
this.byteCount = 0;
this.stream.OnBroadcast += OnStreamBroadcast;
if (this.stream.Start.CanExecute(this))
{
this.stream.Start.Execute(this);
return true;
}
return false;
}
示例5: Start
public bool Start(IAudioStream stream)
{
this.stream = stream;
this.stream.OnBroadcast += HandleOnBroadcast;
this.description = new AudioStreamBasicDescription (AudioFormatType.LinearPCM)
{
BitsPerChannel = stream.BitsPerSample / stream.ChannelCount,
};
}
示例6: Flow
public int Flow(IAudioStream input, short[] obuf, int count, int volLeft, int volRight)
{
var obufPos = 0;
var inPos = 0;
var oend = count;
while (obufPos < oend)
{
// read enough input samples so that opos < 0
while (FRAC_ONE_LOW <= opos)
{
// Check if we have to refill the buffer
if (inLen == 0)
{
inPos = 0;
inLen = input.ReadBuffer(inBuf, RateHelper.IntermediateBufferSize);
if (inLen <= 0)
return obufPos / 2;
}
inLen -= (stereo ? 2 : 1);
ilast0 = icur0;
icur0 = inBuf[inPos++];
if (stereo)
{
ilast1 = icur1;
icur1 = inBuf[inPos++];
}
opos -= FRAC_ONE_LOW;
}
// Loop as long as the outpos trails behind, and as long as there is
// still space in the output buffer.
while (opos < FRAC_ONE_LOW && obufPos < oend)
{
// interpolate
int out0, out1;
out0 = (short)(ilast0 + (((icur0 - ilast0) * opos + FRAC_HALF_LOW) >> FRAC_BITS_LOW));
out1 = stereo ? (short)(ilast1 + (((icur1 - ilast1) * opos + FRAC_HALF_LOW) >> FRAC_BITS_LOW)) : out0;
// output left channel
RateHelper.ClampedAdd(ref obuf[obufPos + (reverseStereo ? 1 : 0)], (out0 * volLeft) / Mixer.MaxMixerVolume);
// output right channel
RateHelper.ClampedAdd(ref obuf[obufPos + (reverseStereo ? 0 : 1)], (out1 * volRight) / Mixer.MaxMixerVolume);
obufPos += 2;
// Increment output position
opos += oposInc;
}
}
return obufPos / 2;
}
示例7: CreateBuffer
public override AudioBuffer CreateBuffer(IAudioStream target)
{
int size = AudioBuffer.DefaultBufferSpan * target.Frequency * target.Channels * target.BitsPerSample / 8;
WaveFormatEx fmt = new WaveFormatEx(target.Format, target.Channels, target.Frequency, target.BitsPerSample);
DS.DSBufferCapsFlags flags = DS.DSBufferCapsFlags.CtrlVolume | DS.DSBufferCapsFlags.LocDefer | DS.DSBufferCapsFlags.GlobalFocus | DS.DSBufferCapsFlags.GetCurrentPosition2;
DS.DSBufferDesc desc = new DS.DSBufferDesc((uint)size, flags, &fmt, Guid.Empty);
return new wAudioBuffer(this, ref desc) { _source = target, _owner = this };
}
示例8: Test1
public bool Test1(IAudioStream audio, int state)
{
if (state == 0)
Debug.WriteLine("Test #1: play, pause, stop and global stop");
if (state == 2)
{
Debug.WriteLine("----> play for five seconds");
audio.Play();
}
if (state == 7)
{
Debug.WriteLine("----> pause music for two seconds");
audio.Pause();
}
if (state == 9)
{
Debug.WriteLine("----> play music for five seconds");
audio.Play();
}
if (state == 14)
{
Debug.WriteLine("----> stop music for two seconds");
audio.Stop();
}
if (state == 16)
{
Debug.WriteLine("----> play music for five seconds");
audio.Play();
}
if (state == 21)
{
Debug.WriteLine("----> global stop for two seconds");
Audio.Instance.Stop();
}
if (state == 23)
{
Debug.WriteLine("----> play music for five seconds");
audio.Play();
}
if (state != 28)
return false;
audio.Stop();
return true;
}
示例9: Test2
public bool Test2(IAudioStream audio, int state)
{
if (state == 0)
Debug.WriteLine("Test #2: lower global volume from 100 to 0");
if (state >= 2)
{
Audio.Instance.SetVolume(100 - ((state - 2)*20));
Debug.WriteLine("----> global volume set to: " + Audio.Instance.GetVolume());
audio.Play();
}
return state == 7;
}
示例10: Flow
public int Flow(IAudioStream input, short[] obuf, int count, int volLeft, int volRight)
{
int pos = 0;
int oend = count * 2;
while (pos < oend)
{
// read enough input samples so that opos >= 0
do
{
// Check if we have to refill the buffer
if (inLen == 0)
{
inPtr = 0;
inLen = input.ReadBuffer(inBuf, RateHelper.IntermediateBufferSize);
if (inLen <= 0)
return pos / 2;
}
inLen -= (stereo ? 2 : 1);
opos--;
if (opos >= 0)
{
inPtr += (stereo ? 2 : 1);
}
} while (opos >= 0);
short out0, out1;
out0 = inBuf[inPtr++];
out1 = (stereo ? inBuf[inPtr++] : out0);
// Increment output position
opos += oposInc;
// output left channel
RateHelper.ClampedAdd(ref obuf[reverseStereo ? 1 : 0], (out0 * (int)volLeft) / Mixer.MaxMixerVolume);
// output right channel
RateHelper.ClampedAdd(ref obuf[(reverseStereo ? 1 : 0) ^ 1], (out1 * (int)volRight) / Mixer.MaxMixerVolume);
pos += 2;
}
return pos / 2;
}
示例11: Test3
public bool Test3(IAudioStream audio, int state)
{
if (state == 0)
{
Audio.Instance.SetVolume(100);
audio.Volume = 0;
Debug.WriteLine("Test #3: raise individual volume from 0 to 100");
}
if (state >= 2)
{
audio.Volume = ((state - 2)*20);
Debug.WriteLine("----> individual volume set to: " + audio.Volume);
audio.Play();
}
return (state == 7);
}
示例12: PlayStream
public SoundHandle PlayStream(SoundType type, IAudioStream stream, int id = -1, int volume = 255,
int balance = 0, bool autofreeStream = true, bool permanent = false, bool reverseStereo = false)
{
lock (_gate)
{
if (stream == null)
{
// Console.Error.WriteLine("stream is null");
return new SoundHandle();
}
Debug.Assert(IsReady);
// Prevent duplicate sounds
if (id != -1)
{
for (var i = 0; i != NumChannels; i++)
if (_channels[i] != null && _channels[i].Id == id)
{
// Delete the stream if were asked to auto-dispose it.
// Note: This could cause trouble if the client code does not
// yet expect the stream to be gone. The primary example to
// keep in mind here is QueuingAudioStream.
// Thus, as a quick rule of thumb, you should never, ever,
// try to play QueuingAudioStreams with a sound id.
if (autofreeStream)
stream.Dispose();
return new SoundHandle();
}
}
// Create the channel
var chan = new Channel(this, type, stream, autofreeStream, reverseStereo, id, permanent)
{
Volume = volume,
Balance = balance
};
return InsertChannel(chan);
}
}
示例13: Flow
public int Flow(IAudioStream input, short[] obuf, int count, int volLeft, int volRight)
{
Debug.Assert(input.IsStereo == stereo);
var osamp = count / 2;
if (stereo)
osamp *= 2;
// Reallocate temp buffer, if necessary
if (osamp > _bufferSize)
{
_buffer = new short[osamp];
_bufferSize = osamp;
}
// Read up to 'osamp' samples into our temporary buffer
var len = input.ReadBuffer(_buffer, _bufferSize);
int iPos = 0;
var oPos = 0;
var inc = stereo ? 2 : 1;
// Mix the data into the output buffer
for (; iPos < len; iPos += inc)
{
var out0 = _buffer[iPos];
var out1 = stereo ? _buffer[iPos + 1] : out0;
// output left channel
RateHelper.ClampedAdd(ref obuf[oPos + (reverseStereo ? 1 : 0)], (out0 * volLeft) / Mixer.MaxMixerVolume);
// output right channel
RateHelper.ClampedAdd(ref obuf[oPos + (reverseStereo ? 0 : 1)], (out1 * volRight) / Mixer.MaxMixerVolume);
oPos += 2;
}
return oPos / 2;
}
示例14: StartRecorder
public async Task<bool> StartRecorder(IAudioStream stream, Stream fileStream, int sampleRate)
{
if (this.stream != null || stream == null)
{
return false;
}
this.stream = stream;
try
{
this.writer = new BinaryWriter(fileStream, Encoding.UTF8);
}
catch (Exception)
{
return false;
}
this.byteCount = 0;
this.stream.OnBroadcast += OnStreamBroadcast;
return await this.stream.Start(sampleRate);
}
示例15: Init
public override void Init()
{
RC.ClearColor = new float4(0, 0, 0, 1);
Mesh = new Cube();
var sp = MoreShaders.GetDiffuseColorShader(RC);
RC.SetShader(sp);
_vColor = RC.GetShaderParam(sp, "color");
RC.SetShaderParam(_vColor, new float4(0.8f, 0.1f, 0.1f, 1));
// sound by http://www.soundjay.com
_audio1 = Audio.Instance.LoadFile("Assets/beep.ogg");
// excerpt from "the final rewind" by tryad (http://www.tryad.org) - cc-by-sa
_audio2 = Audio.Instance.LoadFile("Assets/music.ogg");
_state = 0;
_testID = 1;
_timeStep = 1.0f;
_curTime = 2.0f;
_tests = new Tests();
}