Browse Source

Added experimental NSpeex plugin for Network Chat demo. Currently not fully working. Had to create a .NET 3.5 build of NSpeex

pull/1/head
markheath 14 years ago
parent
commit
ca607d8bb6
  1. BIN
      Lib/NSpeex/NSpeex.dll
  2. 4
      NAudioDemo/NAudioDemo.csproj
  3. 3
      NAudioDemo/NetworkChatDemo/NetworkChatPanel.cs
  4. 65
      NAudioDemo/NetworkChatDemo/SpeexChatCodec.cs

BIN
Lib/NSpeex/NSpeex.dll

4
NAudioDemo/NAudioDemo.csproj

@ -54,6 +54,9 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="NSpeex">
<HintPath>..\Lib\NSpeex\NSpeex.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition">
<HintPath>..\Lib\MEF\System.ComponentModel.Composition.dll</HintPath>
@ -122,6 +125,7 @@
<Compile Include="NetworkChatDemo\NetworkChatPanel.Designer.cs">
<DependentUpon>NetworkChatPanel.cs</DependentUpon>
</Compile>
<Compile Include="NetworkChatDemo\SpeexChatCodec.cs" />
<Compile Include="NetworkChatDemo\TrueSpeechChatCodec.cs" />
<Compile Include="NetworkChatDemo\UncompressedPcmChatCodec.cs" />
<Compile Include="Program.cs" />

3
NAudioDemo/NetworkChatDemo/NetworkChatPanel.cs

@ -48,7 +48,8 @@ namespace NAudioDemo.NetworkChatDemo
new TrueSpeechChatCodec(),
new Gsm610ChatCodec(),
new MicrosoftAdpcmChatCodec(),
new G722ChatCodec()
new G722ChatCodec(),
// new SpeexChatCodec(), - still work in progress
};
var sorted = from codec in codecs orderby codec.BitsPerSecond ascending select codec;

65
NAudioDemo/NetworkChatDemo/SpeexChatCodec.cs

@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NAudio.Wave;
using NSpeex;
namespace NAudioDemo.NetworkChatDemo
{
class SpeexChatCodec : INetworkChatCodec
{
private WaveFormat recordingFormat;
private SpeexDecoder decoder;
private SpeexEncoder encoder;
public SpeexChatCodec()
{
this.decoder = new SpeexDecoder(BandMode.Narrow);
this.encoder = new SpeexEncoder(BandMode.Narrow);
this.recordingFormat = new WaveFormat(8000, 16, 1);
}
public string Name
{
get { return "Speex Narrow Band"; }
}
public int BitsPerSecond
{
// don't know yet
get { return 8000; }
}
public WaveFormat RecordFormat
{
get { return recordingFormat; }
}
public byte[] Encode(byte[] data, int offset, int length)
{
byte[] outputBufferTemp = new byte[length]; // easily big enough
WaveBuffer wb = new WaveBuffer(data);
int bytesWritten = encoder.Encode(wb.ShortBuffer, offset / 2, length / 2, outputBufferTemp, 0, length);
byte[] encoded = new byte[bytesWritten];
Array.Copy(outputBufferTemp, 0, encoded, 0, bytesWritten);
return encoded;
}
public byte[] Decode(byte[] data)
{
byte[] outputBufferTemp = new byte[data.Length * 16]; // easily big enough
WaveBuffer wb = new WaveBuffer(outputBufferTemp);
int samplesWritten = decoder.Decode(data, 0, data.Length, wb.ShortBuffer, 0, false);
int bytesWritten = samplesWritten * 2;
byte[] decoded = new byte[bytesWritten];
Array.Copy(outputBufferTemp, 0, decoded, 0, bytesWritten);
return decoded;
}
public void Dispose()
{
// nothing to do
}
}
}
Loading…
Cancel
Save