added dependencies and build files (loosely inspired by Sebastian Dorda's love-native-android)

This commit is contained in:
Martin Felis
2013-12-05 17:58:37 +01:00
parent 9604528a96
commit 95a086a47f
3700 changed files with 1691119 additions and 0 deletions
@@ -0,0 +1,435 @@
/*
replacereaderclr: test program for mpg123clr, showing how to use ReplaceReader in a CLR enviro.
copyright 2009 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Malcolm Boczek
not to be used as an example of good coding practices, note the total absence of error handling!!!
*/
/*
1.9.0.0 24-Sep-09 Function names harmonized with libmpg123 (mb)
1.12.0.0 14-Apr-10 Added ReplaceReaderHandle sample code (mb)
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; // for ReplaceReaderHandle example
using System.Runtime.InteropServices; // for ReplaceReaderHandle example
using mpg123clr;
namespace ReplaceReaderclr
{
class Program
{
private unsafe static int MyReadFunc(int a, void* b, uint c)
{
// need to call posix read function here...
// PosixRead is an example, substitute your replacement function here.
int ret = mpg123.PosixRead(a, b, c);
return ret;
}
private static int MySeekFunc(int a, int b, int c)
{
// NOTE: Largefile conflict with use of "int" position values.
// Convert to long if off_t is defined as long long
// need to call posix lseek function here...
// PosixSeek is an example, substitute your replacement function here.
int ret = mpg123.PosixSeek(a, b, c);
return ret;
}
private unsafe static int MyHandleReadFunc(void* a, void* b, uint c)
{
GCHandle gch = GCHandle.FromIntPtr((IntPtr)a);
BinaryReader br = (BinaryReader)gch.Target;
byte[] buf = br.ReadBytes((int)c);
// NOTE: no discernible performance difference between Marshal.Copy and ptr++ loop
Marshal.Copy(buf, 0, (IntPtr)b, buf.Length);
// byte* ptr = (byte*)b;
// for (int i = 0, l = buf.Length; i < l; i++)
// *(ptr++) = buf[i];
return buf.Length;
}
private unsafe static int MyHandleSeekFunc(void* a, int b, int c)
{
// NOTE: Largefile conflict with use of "int" position values.
// Convert to long if off_t is defined as long long
GCHandle gch = GCHandle.FromIntPtr((IntPtr)a);
BinaryReader br = (BinaryReader)gch.Target;
return (int)br.BaseStream.Seek(b, (SeekOrigin)c);
}
private unsafe static void MyHandleCleanFunc(void* a)
{
GCHandle gch = GCHandle.FromIntPtr((IntPtr)a);
BinaryReader br = (BinaryReader)gch.Target;
br.Close();
}
static unsafe void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("I need a file to work on:\n\nPress any key to exit.");
while (Console.Read() == 0) ;
return;
}
mpg123clr.mpg.ErrorCode err;
string filename = args[0];
err = mpg123.mpg123_init();
Console.WriteLine("Init:");
RunReplaceReaderTest(filename);
RunReplaceReaderHandleTest(filename);
RunFrameByFrameTest(filename);
Console.WriteLine("\nPress any key to exit:");
while (Console.Read() == 0) ;
mpg123.mpg123_exit();
}
static unsafe void RunReplaceReaderTest(string filename)
{
mpg123clr.mpg.ErrorCode err;
mpg123 mp = new mpg123();
err = mp.mpg123_new();
// ReplaceReader example
mpg123clr.mpg123.ReadDelegate rdel = MyReadFunc;
mpg123clr.mpg123.SeekDelegate sdel = MySeekFunc;
err = mp.mpg123_replace_reader(rdel, sdel);
//err = mp.mpg123_open(args[0]);
err = mp.mpg123_open(filename);
if (err != mpg123clr.mpg.ErrorCode.ok)
{
Console.WriteLine("Error: " + mp.mpg123_strerror());
}
else
{
Console.WriteLine("Open:");
// Show available decoders
string[] Decoders = mp.mpg123_decoders();
if (Decoders.Length > 0)
{
Console.WriteLine("\nDecoders:");
foreach (string str in Decoders) Console.WriteLine(str);
}
// Show supported decoders
string[] supDecoders = mp.mpg123_supported_decoders();
if (supDecoders.Length > 0)
{
Console.WriteLine("\nSupported Decoders:");
foreach (string str in supDecoders) Console.WriteLine(str);
}
// Show actual decoder
Console.WriteLine("\nDecoder: " + mp.mpg123_current_decoder());
// Show estimated file length
Console.WriteLine("\nLength Estimate: " + mp.mpg123_length().ToString());
// Scan - gets actual details including ID3v2 and Frame offsets
err = mp.mpg123_scan();
// Show actual file length
if (err == mpg123clr.mpg.ErrorCode.ok) Console.WriteLine("Length Actual : " + mp.mpg123_length().ToString());
// Get ID3 data
mpg123clr.id3.mpg123id3v1 iv1;
mpg123clr.id3.mpg123id3v2 iv2;
err = mp.mpg123_id3(out iv1, out iv2);
// Show ID3v2 data
Console.WriteLine("\nTitle : " + iv2.title);
Console.WriteLine("Artist : " + iv2.artist);
Console.WriteLine("Album : " + iv2.album);
Console.WriteLine("Comment: " + iv2.comment);
Console.WriteLine("Year : " + iv2.year);
// Demo seek (back to start of file - note: scan should already have done this)
long pos = mp.mpg123_seek(0, System.IO.SeekOrigin.Begin);
long[] frameindex;
long step;
err = mp.mpg123_index(out frameindex, out step);
if (err == mpg123clr.mpg.ErrorCode.ok)
{
Console.WriteLine("\nFrameIndex:");
foreach (long idx in frameindex)
{
// Console.WriteLine(idx.ToString());
}
}
int num;
uint cnt;
IntPtr audio;
// Walk the file - effectively decode the data without using it...
Console.WriteLine("\nWalking : " + iv2.title);
DateTime dte, dts = DateTime.Now;
while (err == mpg123clr.mpg.ErrorCode.ok || err == mpg123clr.mpg.ErrorCode.new_format)
{
err = mp.mpg123_decode_frame(out num, out audio, out cnt);
// do something with "audio" here....
}
dte = DateTime.Now;
TimeSpan ts = dte - dts;
Console.WriteLine("Duration: " + ts.ToString());
mp.mpg123_close();
}
mp.Dispose();
}
static unsafe void RunReplaceReaderHandleTest(string filename)
{
mpg123clr.mpg.ErrorCode err;
mpg123 mp = new mpg123();
err = mp.mpg123_new();
// ReplaceReader example
mpg123clr.mpg123.ReadHandleDelegate rdel = MyHandleReadFunc;
mpg123clr.mpg123.SeekHandleDelegate sdel = MyHandleSeekFunc;
mpg123clr.mpg123.CleanupHandleDelegate cdel = MyHandleCleanFunc;
err = mp.mpg123_replace_reader_handle(rdel, sdel, cdel);
//err = mp.mpg123_open(args[0]);
BinaryReader br = new BinaryReader(File.OpenRead(filename));
err = mp.mpg123_open_handle(br);
if (err != mpg123clr.mpg.ErrorCode.ok)
{
Console.WriteLine("Error: " + mp.mpg123_strerror());
}
else
{
Console.WriteLine("Open:");
// Show available decoders
string[] Decoders = mp.mpg123_decoders();
if (Decoders.Length > 0)
{
Console.WriteLine("\nDecoders:");
foreach (string str in Decoders) Console.WriteLine(str);
}
// Show supported decoders
string[] supDecoders = mp.mpg123_supported_decoders();
if (supDecoders.Length > 0)
{
Console.WriteLine("\nSupported Decoders:");
foreach (string str in supDecoders) Console.WriteLine(str);
}
// Show actual decoder
Console.WriteLine("\nDecoder: " + mp.mpg123_current_decoder());
// Show estimated file length
Console.WriteLine("\nLength Estimate: " + mp.mpg123_length().ToString());
// Scan - gets actual details including ID3v2 and Frame offsets
err = mp.mpg123_scan();
// Show actual file length
if (err == mpg123clr.mpg.ErrorCode.ok) Console.WriteLine("Length Actual : " + mp.mpg123_length().ToString());
// Get ID3 data
mpg123clr.id3.mpg123id3v1 iv1;
mpg123clr.id3.mpg123id3v2 iv2;
err = mp.mpg123_id3(out iv1, out iv2);
// Show ID3v2 data
Console.WriteLine("\nTitle : " + iv2.title);
Console.WriteLine("Artist : " + iv2.artist);
Console.WriteLine("Album : " + iv2.album);
Console.WriteLine("Comment: " + iv2.comment);
Console.WriteLine("Year : " + iv2.year);
// Demo seek (back to start of file - note: scan should already have done this)
long pos = mp.mpg123_seek(0, System.IO.SeekOrigin.Begin);
long[] frameindex;
long step;
err = mp.mpg123_index(out frameindex, out step);
if (err == mpg123clr.mpg.ErrorCode.ok)
{
Console.WriteLine("\nFrameIndex:");
foreach (long idx in frameindex)
{
// Console.WriteLine(idx.ToString());
}
}
int num;
uint cnt;
IntPtr audio;
// Walk the file - effectively decode the data without using it...
Console.WriteLine("\nWalking : " + iv2.title);
DateTime dte, dts = DateTime.Now;
while (err == mpg123clr.mpg.ErrorCode.ok || err == mpg123clr.mpg.ErrorCode.new_format)
{
err = mp.mpg123_decode_frame(out num, out audio, out cnt);
// do something with "audio" here....
}
dte = DateTime.Now;
TimeSpan ts = dte - dts;
Console.WriteLine("Duration: " + ts.ToString());
mp.mpg123_close();
}
mp.Dispose();
}
static unsafe void RunFrameByFrameTest(string filename)
{
mpg123clr.mpg.ErrorCode err;
mpg123 mp = new mpg123();
err = mp.mpg123_new();
err = mp.mpg123_open(filename);
if (err != mpg123clr.mpg.ErrorCode.ok)
{
Console.WriteLine("Error: " + mp.mpg123_strerror());
}
else
{
Console.WriteLine("Open:");
// Show available decoders
string[] Decoders = mp.mpg123_decoders();
if (Decoders.Length > 0)
{
Console.WriteLine("\nDecoders:");
foreach (string str in Decoders) Console.WriteLine(str);
}
// Show supported decoders
string[] supDecoders = mp.mpg123_supported_decoders();
if (supDecoders.Length > 0)
{
Console.WriteLine("\nSupported Decoders:");
foreach (string str in supDecoders) Console.WriteLine(str);
}
// Show actual decoder
Console.WriteLine("\nDecoder: " + mp.mpg123_current_decoder());
// Show estimated file length
Console.WriteLine("\nLength Estimate: " + mp.mpg123_length().ToString());
// Scan - gets actual details including ID3v2 and Frame offsets
err = mp.mpg123_scan();
// Show actual file length
if (err == mpg123clr.mpg.ErrorCode.ok) Console.WriteLine("Length Actual : " + mp.mpg123_length().ToString());
// Get ID3 data
mpg123clr.id3.mpg123id3v1 iv1;
mpg123clr.id3.mpg123id3v2 iv2;
err = mp.mpg123_id3(out iv1, out iv2);
// Show ID3v2 data
Console.WriteLine("\nTitle : " + iv2.title);
Console.WriteLine("Artist : " + iv2.artist);
Console.WriteLine("Album : " + iv2.album);
Console.WriteLine("Comment: " + iv2.comment);
Console.WriteLine("Year : " + iv2.year);
// Demo seek (back to start of file - note: scan should already have done this)
long pos = mp.mpg123_seek(0, System.IO.SeekOrigin.Begin);
long[] frameindex;
long step;
err = mp.mpg123_index(out frameindex, out step);
if (err == mpg123clr.mpg.ErrorCode.ok)
{
Console.WriteLine("\nFrameIndex:");
foreach (long idx in frameindex)
{
// Console.WriteLine(idx.ToString());
}
}
int num;
uint cnt;
IntPtr audio;
// Walk the file - effectively decode the data without using it...
Console.WriteLine("\nFrame Walking : " + iv2.title);
DateTime dte, dts = DateTime.Now;
while (err == mpg123clr.mpg.ErrorCode.ok || err == mpg123clr.mpg.ErrorCode.new_format)
{
err = mp.mpg123_framebyframe_decode(out num, out audio, out cnt);
err = mp.mpg123_framebyframe_next();
// do something with "audio" here....
}
dte = DateTime.Now;
TimeSpan ts = dte - dts;
Console.WriteLine("Duration: " + ts.ToString());
mp.mpg123_close();
}
mp.Dispose();
}
}
}
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ReplaceReaderclr")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ReplaceReaderclr")]
[assembly: AssemblyCopyright("© mpg123 project 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("c65bdebb-51d7-41ba-875d-b2c938f187fc")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6415FBC0-44EC-4158-8A24-127D9BAC5CEA}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ReplaceReaderclr</RootNamespace>
<AssemblyName>ReplaceReaderclr</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\mpg123clr\mpg123clr.vcproj">
<Project>{99E8B20E-9C29-46BC-B766-A50F237D88BF}</Project>
<Name>mpg123clr</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<PostBuildEvent>if exist "$(SolutionDir)$(ConfigurationName)\libmpg123.dll" copy /y "$(SolutionDir)$(ConfigurationName)\libmpg123.dll" "$(TargetDir)"</PostBuildEvent>
</PropertyGroup>
</Project>
@@ -0,0 +1,331 @@
/*
feedseekclr: test program for mpg123clr, showing how to use fuzzy seeking in feeder mode
copyright 2009 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
based on feedseek.c example for libmpg123.
Comment (Malcolm Boczek)
this CLR example has been written to allow easy comparison to the original feedseek.c example
and uses some constructs that would not normally be used in a C# environment,
eg: byte[]/ASCII text, Marshal.Copy, static fields, lots of casts etc.
*/
/*
1.9.0.0 24-Sep-09 Function names harmonized with libmpg123 (mb)
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
using mpg123clr;
namespace feedseekclr
{
class Program
{
const int WAVE_FORMAT_PCM = 0x0001;
const int WAVE_FORMAT_IEEE_FLOAT = 0x0003;
static BinaryWriter _out;
static long totaloffset, dataoffset;
static int rate;
static mpg123clr.mpg.channelcount channels;
static mpg123clr.mpg.enc enc;
static short bitspersample, wavformat;
// write wav header
static void initwav()
{
uint tmp32 = 0;
ushort tmp16 = 0;
byte[] rifftxt = new byte[] { (byte)'R', (byte)'I', (byte)'F', (byte)'F' };
byte[] wavetxt = new byte[] { (byte)'W', (byte)'A', (byte)'V', (byte)'E' };
byte[] fmttxt = new byte[] { (byte)'f', (byte)'m', (byte)'t', (byte)' ' };
byte[] datatxt = new byte[] { (byte)'d', (byte)'a', (byte)'t', (byte)'a' };
_out.Write(rifftxt);
totaloffset = _out.BaseStream.Position;
_out.Write(tmp32); // total size
_out.Write(wavetxt);
_out.Write(fmttxt);
tmp32 = 16;
_out.Write(tmp32); // format length
tmp16 = (ushort)wavformat;
_out.Write(tmp16); // format
tmp16 = (ushort)channels;
_out.Write(tmp16); // channels
tmp32 = (uint)rate;
_out.Write(tmp32); // sample rate
tmp32 = (uint) (rate * bitspersample / 8 * (int)channels);
_out.Write(tmp32); // bytes / second
tmp16 = (ushort)(bitspersample / 8 * (int)channels); // float 16 or signed int 16
_out.Write(tmp16); // block align
tmp16 = (ushort)bitspersample;
_out.Write(tmp16); // bits per sample
_out.Write(datatxt);
tmp32 = 0;
dataoffset = _out.BaseStream.Position;
_out.Write(tmp32); // data length
}
// rewrite wav header with final length infos
static void closewav()
{
uint tmp32 = 0;
// ushort tmp16 = 0;
int total = (int)_out.BaseStream.Position;
_out.Seek((int)totaloffset, SeekOrigin.Begin);
tmp32 = (uint)(total - (totaloffset + 4));
_out.Write(tmp32);
_out.Seek((int)dataoffset, SeekOrigin.Begin);
tmp32 = (uint)(total - (dataoffset + 4));
_out.Write(tmp32);
}
// determine correct wav format and bits per sample
// from mpg123 enc value
static void initwavformat()
{
if ((enc & mpg123clr.mpg.enc.enc_float_64) != 0)
{
bitspersample = 64;
wavformat = WAVE_FORMAT_IEEE_FLOAT;
}
else if ((enc & mpg123clr.mpg.enc.enc_float_32) != 0)
{
bitspersample = 32;
wavformat = WAVE_FORMAT_IEEE_FLOAT;
}
else if ((enc & mpg123clr.mpg.enc.enc_16) != 0)
{
bitspersample = 16;
wavformat = WAVE_FORMAT_PCM;
}
else
{
bitspersample = 8;
wavformat = WAVE_FORMAT_PCM;
}
}
static void Main(string[] args)
{
const long INBUFF = 16384 * 2 * 2;
int ret;
mpg123clr.mpg.ErrorCode state;
long inoffset,inc = 0;
long outc = 0;
byte[] buf = new byte[INBUFF];
if (args.Length < 2)
{
Console.WriteLine("Please supply in and out filenames\n");
Console.WriteLine("Press any key to exit:");
while (Console.Read() == 0) ;
return;
}
mpg123clr.mpg.ErrorCode err;
err = mpg123.mpg123_init();
mpg123 mp = new mpg123();
err = mp.mpg123_new();
if (err != mpg123clr.mpg.ErrorCode.ok)
{
Console.WriteLine("Unable to create mpg123 handle: " + mpg123error.mpg123_plain_strerror(err));
Console.WriteLine("Press any key to exit:");
while (Console.Read() == 0) ;
return;
}
mp.mpg123_param(mpg123clr.mpg.parms.verbose, 4, 0);
err = mp.mpg123_param(mpg123clr.mpg.parms.flags,
(int) (mpg123clr.mpg.param_flags.fuzzy |
mpg123clr.mpg.param_flags.seekbuffer |
mpg123clr.mpg.param_flags.gapless), 0);
if (err != mpg123clr.mpg.ErrorCode.ok)
{
Console.WriteLine("Unable to set library options: " + mp.mpg123_strerror());
Console.WriteLine("Press any key to exit:");
while (Console.Read() == 0) ;
return;
}
// Let the seek index auto-grow and contain an entry for every frame
err = mp.mpg123_param(mpg123clr.mpg.parms.index_size, -1, 0);
if (err != mpg123clr.mpg.ErrorCode.ok)
{
Console.WriteLine("Unable to set index size: " + mp.mpg123_strerror());
Console.WriteLine("Press any key to exit:");
while (Console.Read() == 0) ;
return;
}
// Use float output formats only
err = mp.mpg123_format_none();
if (err != mpg123clr.mpg.ErrorCode.ok)
{
Console.WriteLine("Unable to disable all output formats: " + mp.mpg123_strerror());
Console.WriteLine("Press any key to exit:");
while (Console.Read() == 0) ;
return;
}
int[] rates = mp.mpg123_rates();
foreach (int rate in rates)
{
err = mp.mpg123_format(rate, mpg123clr.mpg.channelcount.both, mpg123clr.mpg.enc.enc_float_32);
if (err != mpg123clr.mpg.ErrorCode.ok)
{
Console.WriteLine("Unable to set float output formats: " + mp.mpg123_strerror());
Console.WriteLine("Press any key to exit:");
while (Console.Read() == 0) ;
return;
}
}
err = mp.mpg123_open_feed();
if (err != mpg123clr.mpg.ErrorCode.ok)
{
Console.WriteLine("Unable to open feed: " + mp.mpg123_strerror());
Console.WriteLine("Press any key to exit:");
while (Console.Read() == 0) ;
return;
}
string filename = args[0];
BinaryReader _in = new BinaryReader(File.Open(filename, FileMode.Open));
_out = new BinaryWriter(File.Open(args[1], FileMode.Create));
while ((ret = (int)(mp.mpg123_feedseek(95000, SeekOrigin.Begin, out inoffset))) == (int)mpg123clr.mpg.ErrorCode.need_more) // equiv to mpg123_feedseek
{
buf = _in.ReadBytes((int)INBUFF);
if (buf.Length <= 0) break;
inc += buf.Length;
state = mp.mpg123_feed(buf, (uint)buf.Length);
if (state == mpg123clr.mpg.ErrorCode.err)
{
Console.WriteLine("Feed error: " + mp.mpg123_strerror());
Console.WriteLine("Press any key to exit:");
while (Console.Read() == 0) ;
return;
}
}
_in.BaseStream.Seek(inoffset, SeekOrigin.Begin);
while (true)
{
buf = _in.ReadBytes((int)INBUFF);
if (buf.Length <= 0) break;
inc += buf.Length;
err = mp.mpg123_feed(buf, (uint)buf.Length);
int num;
uint bytes;
IntPtr audio;
while (err != mpg123clr.mpg.ErrorCode.err && err != mpg123clr.mpg.ErrorCode.need_more)
{
err = mp.mpg123_decode_frame(out num, out audio, out bytes);
if (err == mpg123clr.mpg.ErrorCode.new_format)
{
mp.mpg123_getformat(out rate, out channels, out enc);
initwavformat();
initwav();
}
// (Surprisingly?) even though it does a Marshal.Copy it's as efficient as the pointer example below!!!
if (bytes > 0)
{
byte[] outbuf = new byte[bytes];
Marshal.Copy(audio, outbuf, 0, (int)bytes);
_out.Write(outbuf, 0, (int)bytes);
}
// Alternative example of direct usage of audio data via pointers - note it needs "unsafe"
// and I'm fairly sure pointers should be "fixed" first
// if (bytes > 0)
// unsafe{
// byte* p = (byte*)audio;
// for (int ii = 0; ii < bytes; ii++)
// _out.Write(*p++);
// }
outc += bytes;
}
if (err == mpg123clr.mpg.ErrorCode.err)
{
Console.WriteLine("Error: " + mp.mpg123_strerror());
break;
}
}
Console.WriteLine("Finished");
closewav();
_out.Close();
_in.Close();
mp.mpg123_delete();
mp.Dispose();
mpg123.mpg123_exit();
}
}
}
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("feedseekclr")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("feedseekclr")]
[assembly: AssemblyCopyright("© mpg123 project 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("1fdb46e2-eb93-4e8f-8266-0d386215cc75")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{626B52AB-1E46-46FB-A259-03DCE3994BE6}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>feedseekclr</RootNamespace>
<AssemblyName>feedseekclr</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\mpg123clr\mpg123clr.vcproj">
<Project>{99E8B20E-9C29-46BC-B766-A50F237D88BF}</Project>
<Name>mpg123clr</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<PostBuildEvent>if exist "$(SolutionDir)$(ConfigurationName)\libmpg123.dll" copy /y "$(SolutionDir)$(ConfigurationName)\libmpg123.dll" "$(TargetDir)"</PostBuildEvent>
</PropertyGroup>
</Project>
@@ -0,0 +1,79 @@
/*
scanclr: Estimate length (sample count) of a mpeg file and compare to length from exact scan.
copyright 2009 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
CLR example initially written by Malcolm Boczek
Based on scan.c example initially written by Thomas Orgis
*/
/* Note the lack of error checking here.
While it would be nicer to inform the user about troubles, libmpg123 is designed _not_ to bite you on operations with invalid handles , etc.
You just jet invalid results on invalid operations... */
/* Ditto for mpg123clr (MB) */
/*
1.9.0.0 24-Sep-09 Function names harmonized with libmpg123 (mb)
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using mpg123clr;
namespace scanclr
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("\nI will give you the estimated and exact sample lengths of MPEG audio files.\n");
Console.WriteLine("\nUsage: scanclr <mpeg audio file list>\n\n");
Console.WriteLine("Press any key to exit:");
while (Console.Read() == 0) ;
return;
}
mpg123clr.mpg.ErrorCode err;
err = mpg123.mpg123_init();
mpg123 mp = new mpg123();
err = mp.mpg123_new();
mp.mpg123_param(mpg123clr.mpg.parms.resync_limit, -1, 0);
foreach (string name in args)
{
err = mp.mpg123_open(name);
long a, b;
a = mp.mpg123_length();
mp.mpg123_scan();
b = mp.mpg123_length();
mp.mpg123_close();
Console.WriteLine(string.Format("File {0}: estimated {1} vs. scanned {2}", name, a, b));
}
Console.WriteLine("\nPress any key to exit:");
while (Console.Read() == 0) ;
mp.Dispose();
mpg123.mpg123_exit();
}
}
}
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("scanclr")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("scanclr")]
[assembly: AssemblyCopyright("© mpg123 project 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a22ea83e-2dba-4835-b0d8-cca3f0bc73a8")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{53664927-0A21-4056-A5D5-C6A1B4B1F839}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>scanclr</RootNamespace>
<AssemblyName>scanclr</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\mpg123clr\mpg123clr.vcproj">
<Project>{99E8B20E-9C29-46BC-B766-A50F237D88BF}</Project>
<Name>mpg123clr</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<PostBuildEvent>if exist "$(SolutionDir)$(ConfigurationName)\libmpg123.dll" copy /y "$(SolutionDir)$(ConfigurationName)\libmpg123.dll" "$(TargetDir)"</PostBuildEvent>
</PropertyGroup>
</Project>