Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions OpusDemo/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Text;
using System.Windows.Forms;
using NAudio.Wave;
using FragLabs.Audio.Codecs;
using OpusNet;

namespace OpusDemo
{
Expand Down Expand Up @@ -64,9 +64,9 @@ void StartEncoding()
_startTime = DateTime.Now;
_bytesSent = 0;
_segmentFrames = 960;
_encoder = OpusEncoder.Create(48000, 1, FragLabs.Audio.Codecs.Opus.Application.Voip);
_encoder = new OpusEncoder(48000, 1, OpusNet.OpusApplication.Voip);
_encoder.Bitrate = 8192;
_decoder = OpusDecoder.Create(48000, 1);
_decoder = new OpusDecoder(48000, 1);
_bytesPerSegment = _encoder.FrameByteCount(_segmentFrames);

_waveIn = new WaveIn(WaveCallbackInfo.FunctionCallback());
Expand Down
17 changes: 11 additions & 6 deletions OpusDemo/OpusDemo.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -9,27 +9,30 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OpusDemo</RootNamespace>
<AssemblyName>OpusDemo</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x86</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>x86</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="NAudio">
Expand Down Expand Up @@ -66,7 +69,9 @@
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand All @@ -79,9 +84,9 @@
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpusWrapper\OpusWrapper.csproj">
<ProjectReference Include="..\OpusNet\OpusNet.csproj">
<Project>{838bdb0b-5eb1-4c1e-9026-0a8842ac00c6}</Project>
<Name>OpusWrapper</Name>
<Name>OpusNet</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
44 changes: 18 additions & 26 deletions OpusDemo/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 10 additions & 14 deletions OpusDemo/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions OpusDemo/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/></startup></configuration>
52 changes: 26 additions & 26 deletions OpusWrapper.sln → OpusNet.sln
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpusWrapper", "OpusWrapper\OpusWrapper.csproj", "{838BDB0B-5EB1-4C1E-9026-0A8842AC00C6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpusDemo", "OpusDemo\OpusDemo.csproj", "{A015969C-3FC3-456C-87D8-9C5C09B5BA22}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{838BDB0B-5EB1-4C1E-9026-0A8842AC00C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{838BDB0B-5EB1-4C1E-9026-0A8842AC00C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{838BDB0B-5EB1-4C1E-9026-0A8842AC00C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{838BDB0B-5EB1-4C1E-9026-0A8842AC00C6}.Release|Any CPU.Build.0 = Release|Any CPU
{A015969C-3FC3-456C-87D8-9C5C09B5BA22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A015969C-3FC3-456C-87D8-9C5C09B5BA22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A015969C-3FC3-456C-87D8-9C5C09B5BA22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A015969C-3FC3-456C-87D8-9C5C09B5BA22}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpusNet", "OpusNet\OpusNet.csproj", "{838BDB0B-5EB1-4C1E-9026-0A8842AC00C6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpusDemo", "OpusDemo\OpusDemo.csproj", "{A015969C-3FC3-456C-87D8-9C5C09B5BA22}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{838BDB0B-5EB1-4C1E-9026-0A8842AC00C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{838BDB0B-5EB1-4C1E-9026-0A8842AC00C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{838BDB0B-5EB1-4C1E-9026-0A8842AC00C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{838BDB0B-5EB1-4C1E-9026-0A8842AC00C6}.Release|Any CPU.Build.0 = Release|Any CPU
{A015969C-3FC3-456C-87D8-9C5C09B5BA22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A015969C-3FC3-456C-87D8-9C5C09B5BA22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A015969C-3FC3-456C-87D8-9C5C09B5BA22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A015969C-3FC3-456C-87D8-9C5C09B5BA22}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
17 changes: 17 additions & 0 deletions OpusNet/Library.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace OpusNet
{
public static class Library
{
public static string opus_x32 = "opus32.dll";
public static string opus_x64 = "opus64.dll";

public static string opus_dll = IntPtr.Size == 4 ? opus_x32 : opus_x64;

}
}
35 changes: 16 additions & 19 deletions OpusWrapper/OpusDecoder.cs → OpusNet/OpusDecoder.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
using System;
using FragLabs.Audio.Codecs.Opus;

namespace FragLabs.Audio.Codecs
namespace OpusNet
{
/// <summary>
/// Opus audio decoder.
/// </summary>
public class OpusDecoder : IDisposable
{
private IntPtr _decoder;

static OpusDecoder()
{
Wrapper.Initialize();
}

/// <summary>
/// Creates a new Opus decoder.
/// </summary>
/// <param name="outputSampleRate">Sample rate to decode at (Hz). This must be one of 8000, 12000, 16000, 24000, or 48000.</param>
/// <param name="outputChannels">Number of channels to decode.</param>
/// <returns>A new <c>OpusDecoder</c>.</returns>
public static OpusDecoder Create(int outputSampleRate, int outputChannels)
public OpusDecoder(int outputSampleRate, int outputChannels)
{
if (outputSampleRate != 8000 &&
outputSampleRate != 12000 &&
Expand All @@ -26,22 +32,13 @@ public static OpusDecoder Create(int outputSampleRate, int outputChannels)
throw new ArgumentOutOfRangeException("inputChannels");

IntPtr error;
IntPtr decoder = API.opus_decoder_create(outputSampleRate, outputChannels, out error);
this._decoder = Wrapper.opus_decoder_create(outputSampleRate, outputChannels, out error);
if ((Errors)error != Errors.OK)
{
throw new Exception("Exception occured while creating decoder");
}
return new OpusDecoder(decoder, outputSampleRate, outputChannels);
}

private IntPtr _decoder;

private OpusDecoder(IntPtr decoder, int outputSamplingRate, int outputChannels)
{
_decoder = decoder;
OutputSamplingRate = outputSamplingRate;
OutputChannels = outputChannels;
MaxDataBytes = 4000;
this.OutputSamplingRate = outputSampleRate;
this.OutputChannels = outputChannels;
this.MaxDataBytes = 4000;
}

/// <summary>
Expand All @@ -63,9 +60,9 @@ public unsafe byte[] Decode(byte[] inputOpusData, int dataLength, out int decode
fixed (byte* bdec = decoded)
{
decodedPtr = new IntPtr((void*)bdec);
length = API.opus_decode(_decoder, inputOpusData, dataLength, decodedPtr, frameCount, 0);
length = Wrapper.opus_decode(_decoder, inputOpusData, dataLength, decodedPtr, frameCount, 0);
}
decodedLength = length * 2;
decodedLength = length * 2 * OutputChannels;
if (length < 0)
throw new Exception("Decoding failed - " + ((Errors)length).ToString());

Expand Down Expand Up @@ -115,7 +112,7 @@ public void Dispose()

if (_decoder != IntPtr.Zero)
{
API.opus_decoder_destroy(_decoder);
Wrapper.opus_decoder_destroy(_decoder);
_decoder = IntPtr.Zero;
}

Expand Down
Loading