Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

BSEtunes

, 24 Apr 2010
BSEtunes is a MySQL based, full manageable, networkable single or multiuser jukebox application
BSE.Platten.zip
BSE.Platten
BSE.Platten.vssscc
mssccprj.scc
vssver2.scc
BSE.CoverFlow.WPFLib
BSE.CoverFlow.WPFLib.csproj.user
BSE.CoverFlow.WPFLib.csproj.vspscc
mssccprj.scc
vssver2.scc
Images
close.png
exit.png
next.png
next_disabled.png
Note.jpg
pause.png
PlayButton.png
previous.png
previous_disabled.png
stop.png
vssver2.scc
Properties
Settings.settings
vssver2.scc
Resources
vssver2.scc
BSE.Platten.Admin
BSE.Platten.Admin.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
Settings.settings
vssver2.scc
Resources
Album16.gif
BSEadmin.ico
cdimport.png
cdrip.png
cd_hoeren.png
clearsearch.png
DataContainer_MoveFirsHS.png
DataContainer_MoveLastHS.png
DataContainer_MoveNextHS.png
DataContainer_MovePreviousHS.png
DataContainer_NewRecordHS.png
diskinfo.png
DRIVEDSC.png
DRIVENET.png
Edit_UndoHS.png
exportimage.png
findfile.png
FindHS.png
freedb.png
Genre16.png
Image.png
InsertPictureHS.png
Interpret16.png
OptionsHS.png
PieChart3DHS.png
PieChartHS.png
ProtectFormHS.png
RefreshDocViewHS.png
saveHS.png
search.png
song.png
system.png
tagger.png
tools_16.png
vssver2.scc
BSE.Platten.Admin.WinApp
BSE.Platten.Admin.WinApp.csproj.user
BSE.Platten.Admin.WinApp.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
Settings.settings
vssver2.scc
Resources
BSEadmin.ico
vssver2.scc
BSE.Platten.Audio
bse.ico
BSE.Platten.Audio.csproj.vspscc
mssccprj.scc
vssver2.scc
Options
vssver2.scc
Player
vssver2.scc
Properties
vssver2.scc
Resources
FillDownHS.png
FillLeftHS.png
Folder256.png
FolderFind.png
FolderOpen256.png
GoLtrHS.png
MoveNext.png
MovePrevious.png
OptionsHS.png
PauseHS.png
PlayHS.png
Slider.gif
Start.png
StopHS.png
vssver2.scc
WinControls
vssver2.scc
WMFSDK
vssver2.scc
BSE.Platten.BO
BSE.Platten.BO.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
BSE.Platten.Common
BSE.Platten.Common.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
BSEsplash.png
DRIVEDSC.png
DRIVENET.png
Network.png
splash.png
vssver2.scc
BSE.Platten.Covers
BSE.Platten.Covers.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
Settings.settings
vssver2.scc
BSE.Platten.FreeDb
BSE.Platten.FreeDb.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
OpenCD.png
vssver2.scc
BSE.Platten.Ripper
BSE.Platten.Ripper.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
OpenCD.png
OptionsHS.png
vssver2.scc
BSE.Platten.Statistik
BSE.Platten.Statistik.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
BSE.Platten.Tunes
BSE.Platten.Tunes.csproj.user
BSE.Platten.Tunes.csproj.vspscc
mssccprj.scc
vssver2.scc
Filters
vssver2.scc
Properties
Settings.settings
vssver2.scc
Resources
About.png
Album16.gif
AudioCD.png
AudioFile.png
AutoList.png
broadcast.png
BSE.png
BSEAbout.png
BSEsplash.png
BSEtunes.ico
BSE_16.png
cd_hoeren.png
coverflow.png
DataContainer_MoveNextHS.png
delete.gif
diskinfo.png
Filter2HS.png
FindHS.png
Folder256.png
FolderOpen256.png
Genre16.gif
Interpret16.gif
keinBild.gif
NewPlaylist16.gif
OptionsHS.png
PauseHS.png
RefreshDocViewHS.png
Removabledrive.png
saveHS.png
search.png
shuffle.png
Shuffle_icon.png
song.png
splash1.png
StopHS.png
TaskHS.png
TrackInfo.gif
vssver2.scc
wiedergabe16.gif
BSEadminSetup
BSEadminSetup.vdproj
BSEadminSetup.vdproj.vspscc
mssccprj.scc
vssver2.scc
Debug
Release
BSEtunesSetup
BSEtunesSetup.vdproj
BSEtunesSetup.vdproj.vspscc
mssccprj.scc
vssver2.scc
Debug
Release
dll
BSE.CDDrives.DLL
BSE.Charts.DLL
BSE.Configuration.DLL
BSE.RemovableDrives.DLL
BSE.Shell.DLL
BSE.Windows.Forms.DLL
Lame
lame_enc.dll
vssver2.scc
lame-3.97
BSE.Platten_en.zip
BSE.CoverFlow.WPFLib.csproj.user
close.png
exit.png
next.png
next_disabled.png
Note.jpg
pause.png
PlayButton.png
previous.png
previous_disabled.png
stop.png
vssver2.scc
Settings.settings
vssver2.scc
vssver2.scc
BSE.Platten.Admin.csproj.user
Settings.settings
vssver2.scc
Album16.gif
BSEadmin.ico
cdimport.png
cdrip.png
cd_hoeren.png
clearsearch.png
DataContainer_MoveFirsHS.png
DataContainer_MoveLastHS.png
DataContainer_MoveNextHS.png
DataContainer_MovePreviousHS.png
DataContainer_NewRecordHS.png
diskinfo.png
DRIVEDSC.png
DRIVENET.png
Edit_UndoHS.png
exportimage.png
findfile.png
FindHS.png
freedb.png
Genre16.png
Image.png
InsertPictureHS.png
Interpret16.png
OptionsHS.png
PieChart3DHS.png
PieChartHS.png
ProtectFormHS.png
RefreshDocViewHS.png
saveHS.png
search.png
song.png
system.png
tagger.png
tools_16.png
vssver2.scc
BSE.Platten.Admin.WinApp.csproj.user
Settings.settings
vssver2.scc
BSEadmin.ico
vssver2.scc
bse.ico
BSE.Platten.Audio.csproj.user
vssver2.scc
vssver2.scc
vssver2.scc
FillDownHS.png
FillLeftHS.png
Folder256.png
FolderFind.png
FolderOpen256.png
GoLtrHS.png
MoveNext.png
MovePrevious.png
OptionsHS.png
PauseHS.png
PlayHS.png
Slider.gif
Start.png
StopHS.png
vssver2.scc
vssver2.scc
vssver2.scc
BSE.Platten.BO.csproj.user
vssver2.scc
BSE.Platten.Common.csproj.user
vssver2.scc
BSEsplash.png
DRIVEDSC.png
DRIVENET.png
Network.png
splash.png
vssver2.scc
BSE.Platten.Covers.csproj.user
Settings.settings
vssver2.scc
BSE.Platten.FreeDb.csproj.user
vssver2.scc
OpenCD.png
vssver2.scc
AudioWriter
vssver2.scc
BSE.Platten.Ripper.csproj.user
Lame
vssver2.scc
vssver2.scc
OpenCD.png
OptionsHS.png
vssver2.scc
BSE.Platten.Statistik.csproj.user
vssver2.scc
BSE.Platten.Tunes.csproj.user
vssver2.scc
Settings.settings
vssver2.scc
About.png
Album16.gif
AudioCD.png
AudioFile.png
AutoList.png
broadcast.png
BSE.png
BSEAbout.png
BSEsplash.png
BSEtunes.ico
BSE_16.png
cd_hoeren.png
coverflow.png
DataContainer_MoveNextHS.png
delete.gif
diskinfo.png
Filter2HS.png
FindHS.png
Folder256.png
FolderOpen256.png
Genre16.gif
Interpret16.gif
keinBild.gif
NewPlaylist16.gif
OptionsHS.png
PauseHS.png
RefreshDocViewHS.png
Removabledrive.png
saveHS.png
search.png
shuffle.png
Shuffle_icon.png
song.png
splash1.png
StopHS.png
TaskHS.png
TrackInfo.gif
vssver2.scc
wiedergabe16.gif
BSEadminSetup.vdproj
BSEtunesSetup.vdproj
BSE.CDDrives.DLL
BSE.Charts.DLL
BSE.Configuration.DLL
BSE.RemovableDrives.DLL
BSE.Shell.DLL
BSE.ThreadedShell.DLL
BSE.Windows.Forms.DLL
lame_enc.dll
MySQL.chm.zip
MySqlCreateDataBase5x.sql.zip
using System;
using System.IO;
using System.Security.Permissions;
using System.Globalization;
using BSE.Platten.Ripper.Properties;
using BSE.Platten.Ripper.Lame;
using System.Diagnostics.CodeAnalysis;

namespace BSE.Platten.Ripper.AudioWriters
{
	/// <summary>
    /// Writes mp3 types in binary to a stream and supports writing strings in a specific mp3 encoding.
	/// </summary>
	public class MP3Writer :  AudioWriter
	{
		#region FieldsPrivate
		
		private bool m_bClosed;
        private BeConfiguration m_mp3Configuration;
		private byte[] m_inBuffer;
		private byte[] m_outBuffer;
        private uint m_iLameStream;
		private uint m_iInputSamples;
		private uint m_iOutBufferSize;
		private int m_iInBufferPosition;
		
		#endregion

		#region MethodsPublic
        /// <summary>
        /// Initializes a new instance of the <see cref="MP3Writer"/> class based on the supplied stream using ASCII as the encoding for strings and the given input format.
        /// </summary>
        /// <param name="output">The output stream.</param>
        /// <param name="inputDataFormat">The <see cref="WaveFormat"/> input data format.</param>
        public MP3Writer(Stream output, WaveFormat inputDataFormat)
            : this(output, inputDataFormat, new BeConfiguration(inputDataFormat))
		{
		}
        /// <summary>
        /// Initializes a new instance of the <see cref="MP3Writer"/> class based on the supplied stream using ASCII as the encoding for strings and the given configuration.
        /// </summary>
        /// <param name="output">The output stream.</param>
        /// <param name="configuration">The <see cref="MP3WriterConfiguration"/> configuration.</param>
        public MP3Writer(Stream output, MP3WriterConfiguration configuration)
            : this(output, configuration.WaveFormat, configuration.BeConfiguration)
		{
            if (configuration == null)
            {
                throw new ArgumentNullException(
                    string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.IDS_ArgumentNullException, "configuration"));
            }
		}
        /// <summary>
        /// Initializes a new instance of the <see cref="MP3Writer"/> class based on the supplied stream using ASCII as the encoding for strings with the given input format and the mp3 configuration.
        /// </summary>
        /// <param name="output">The output stream.</param>
        /// <param name="inputFormat">The <see cref="WaveFormat"/> input format.</param>
        /// <param name="mp3Configuration">The <see cref="BeConfiguration"/> configuration.</param>
        public MP3Writer(Stream output, WaveFormat inputFormat, BeConfiguration mp3Configuration)
			:base(output, inputFormat)
		{
			try
			{
				this.m_mp3Configuration = mp3Configuration;
				uint LameResult = LameEncDll.NativeMethods.beInitStream(this.m_mp3Configuration, ref this.m_iInputSamples, ref this.m_iOutBufferSize, ref this.m_iLameStream);
				if ( LameResult != LameEncDll.BE_ERR_SUCCESSFUL)
				{
					throw new ApplicationException(string.Format(CultureInfo.InvariantCulture, "Lame_encDll.beInitStream failed with the error code {0}", LameResult));
				}
				this.m_inBuffer = new byte[this.m_iInputSamples * 2]; //Input buffer is expected as short[]
				this.m_outBuffer = new byte[m_iOutBufferSize];
			}
			catch
			{
				base.Close();
				throw;
			}
		}
        /// <summary>
        /// Closes the current <see cref="MP3Writer"/> and the underlying stream.
        /// </summary>
        [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
        public override void Close()
		{
			if (this.m_bClosed == false)
			{
				try
				{
					uint iEncodedSize = 0;
					if ( this.m_iInBufferPosition > 0)
					{
                        if ( LameEncDll.EncodeChunk(this.m_iLameStream, this.m_inBuffer, 0, (uint)this.m_iInBufferPosition, this.m_outBuffer, ref iEncodedSize) == LameEncDll.BE_ERR_SUCCESSFUL )
						{
							if ( iEncodedSize > 0)
							{
                                Write(this.m_outBuffer, 0, (int)iEncodedSize);
							}
						}
					}
					iEncodedSize = 0;
                    if (LameEncDll.NativeMethods.beDeinitStream(this.m_iLameStream, this.m_outBuffer, ref iEncodedSize) == LameEncDll.BE_ERR_SUCCESSFUL)
					{
						if ( iEncodedSize > 0)
						{
                            Write(this.m_outBuffer, 0, (int)iEncodedSize);
						}
					}
				}
				finally
				{
                    LameEncDll.NativeMethods.beCloseStream(this.m_iLameStream);
				}
			}
			this.m_bClosed = true;
		}
		/// <summary>
        /// Writes a region of a byte array to the current stream.
		/// </summary>
        /// <param name="buffer">A byte array containing the data to write.</param>
        /// <param name="index">The starting point in buffer at which to begin writing.</param>
        /// <param name="count">The number of bytes to write.</param>
        [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
        public override void Write(byte[] buffer, int index, int count)
		{
			int iToCopy = 0;
			uint iEncodedSize = 0;
			uint iLameResult;
			while (count > 0)
			{
				if ( this.m_iInBufferPosition > 0 ) 
				{
					iToCopy = Math.Min(count, this.m_inBuffer.Length - this.m_iInBufferPosition);
					Buffer.BlockCopy(buffer, index, this.m_inBuffer, this.m_iInBufferPosition , iToCopy);
					this.m_iInBufferPosition += iToCopy;
					index += iToCopy;
					count -= iToCopy;
					if (this.m_iInBufferPosition >= this.m_inBuffer.Length)
					{
						this.m_iInBufferPosition = 0;
						if ( (iLameResult = LameEncDll.EncodeChunk(this.m_iLameStream, this.m_inBuffer, this.m_outBuffer, ref iEncodedSize)) == LameEncDll.BE_ERR_SUCCESSFUL )
						{
							if ( iEncodedSize > 0)
							{
								base.Write(this.m_outBuffer, 0, (int)iEncodedSize);
							}
						}
						else
						{
							throw new ApplicationException(
                                string.Format(
                                CultureInfo.InvariantCulture,
                                "Lame.LameEncDll.EncodeChunk failed with the error code {0}",
                                iLameResult));
						}
					}
				}
				else
				{
					if (count >= this.m_inBuffer.Length)
					{
						if ( (iLameResult = LameEncDll.EncodeChunk(this.m_iLameStream, buffer, index, (uint)this.m_inBuffer.Length, this.m_outBuffer, ref iEncodedSize)) == LameEncDll.BE_ERR_SUCCESSFUL )
						{
							if ( iEncodedSize > 0)
							{
								base.Write(this.m_outBuffer, 0, (int)iEncodedSize);
							}
						}
						else
						{
							throw new ApplicationException(
                                string.Format(
                                CultureInfo.InvariantCulture,
                                "Lame.LameEncDll.EncodeChunk failed with the error code {0}",
                                iLameResult)); 
						}
						count -= this.m_inBuffer.Length;
						index += this.m_inBuffer.Length;
					}
					else
					{
						Buffer.BlockCopy(buffer, index, this.m_inBuffer, 0, count);
						this.m_iInBufferPosition = count;
						index += count;
						count = 0;
					}
				}
			}
		}
		#endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Uwe Eichkorn

Switzerland Switzerland
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 24 Apr 2010
Article Copyright 2009 by Uwe Eichkorn
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid