diff options
author | carmen rocco <ix9@users.sourceforge.net> | 2004-05-22 14:04:17 +0000 |
---|---|---|
committer | carmen rocco <ix9@users.sourceforge.net> | 2004-05-22 14:04:17 +0000 |
commit | c08df8dda4424f84dbf34df69c71634d408eba7c (patch) | |
tree | e413b56e725312fd3dd03965ee5b0ce21b4f6dd5 | |
parent | 43fe56f639ea3a24954859420b5b329392168cb3 (diff) |
making mp3*~ work on windows
svn path=/trunk/externals/unauthorized/; revision=1755
-rw-r--r-- | mp3amp~/mp3amp~.c | 5 | ||||
-rw-r--r-- | mp3cast~/mp3cast~.c | 157 | ||||
-rw-r--r-- | mp3live~/mp3fileout~.c | 18 | ||||
-rw-r--r-- | mp3live~/mp3streamin~.c | 13 | ||||
-rw-r--r-- | mp3live~/mp3streamout~.c | 133 | ||||
-rw-r--r-- | mp3write~/mp3write~.c | 122 |
6 files changed, 40 insertions, 408 deletions
diff --git a/mp3amp~/mp3amp~.c b/mp3amp~/mp3amp~.c index a8d8ff7..bf93d98 100644 --- a/mp3amp~/mp3amp~.c +++ b/mp3amp~/mp3amp~.c @@ -52,6 +52,8 @@ #define SOCKET_ERROR -1
#else
#include <winsock.h>
+#include <winbase.h>
+#include <io.h>
#endif
#ifdef NT
@@ -64,8 +66,11 @@ #endif
#ifdef NT
#define STRDUP _strdup
+#define MSG_NOSIGNAL 0
+#define sys_closesocket closesocket
#endif
+
#define LAME_AUDIO_CHUNK_SIZE 1152
#define MIN_AUDIO_INPUT 2*LAME_AUDIO_CHUNK_SIZE /* we must have at least n chunks to play a steady sound */
#define INPUT_BUFFER_SIZE 131072 /* data received on the socket : 128k */
diff --git a/mp3cast~/mp3cast~.c b/mp3cast~/mp3cast~.c index c5a4b81..5d7609f 100644 --- a/mp3cast~/mp3cast~.c +++ b/mp3cast~/mp3cast~.c @@ -26,13 +26,6 @@ /* */
/* ---------------------------------------------------------------------------- */
-
-
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-
#include "m_pd.h" /* standard pd stuff */
#include <sys/types.h>
@@ -53,17 +46,15 @@ #include <netdb.h>
#include <time.h>
#include <sys/time.h>
-#include <lame/lame.h> /* lame encoder stuff */
-#include "mpg123.h"
#define SOCKET_ERROR -1
#else
#include <io.h>
#include <windows.h>
#include <winsock.h>
#include <windef.h>
-#include "lame_enc.h" /* lame encoder stuff */
#endif
-
+#include <lame/lame.h>
+#include "mpg123.h"
#define MY_MP3_MALLOC_IN_SIZE 65536
/* max size taken from lame readme */
@@ -74,16 +65,6 @@ static char *mp3cast_version = "mp3cast~: mp3 streamer version 0.3, written by Yves Degoyon";
-#ifndef UNIX
-static HINSTANCE dll = NULL;
-static BEINITSTREAM initStream = NULL;
-static BEENCODECHUNK encodeChunk = NULL;
-static BEDEINITSTREAM deinitStream = NULL;
-static BECLOSESTREAM closeStream = NULL;
-static BEVERSION dllVersion = NULL;
-static BEWRITEVBRHEADER writeVBRHeader = NULL;
-#endif
-
static t_class *mp3cast_class;
typedef struct _mp3cast
@@ -120,9 +101,7 @@ typedef struct _mp3cast t_float x_f; /* float needed for signal input */
-#ifdef UNIX
lame_global_flags *lgfp; /* lame encoder configuration */
-#endif
} t_mp3cast;
@@ -188,27 +167,16 @@ static void mp3cast_encode(t_mp3cast *x) }
/* encode mp3 data */
-#ifndef UNIX
- err = encodeChunk(x->x_lame, x->x_lamechunk, x->x_mp3inbuf, x->x_mp3outbuf, &x->x_mp3size);
-#else
x->x_mp3size = lame_encode_buffer_interleaved(x->lgfp, x->x_mp3inbuf,
x->x_lamechunk/lame_get_num_channels(x->lgfp),
x->x_mp3outbuf, MY_MP3_MALLOC_OUT_SIZE);
// post( "mp3cast~ : encoding returned %d frames", x->x_mp3size );
-#endif
/* check result */
-#ifndef UNIX
- if(err != BE_ERR_SUCCESSFUL)
- {
- closeStream(x->x_lame);
- error("mp3cast~: lameEncodeChunk() failed (%lu)", err);
-#else
if(x->x_mp3size<0)
{
lame_close( x->lgfp );
error("mp3cast~: lame_encode_buffer_interleaved failed (%d)", x->x_mp3size);
-#endif
x->x_lame = -1;
}
}
@@ -224,11 +192,7 @@ static void mp3cast_stream(t_mp3cast *x) if(err < 0)
{
error("mp3cast~: could not send encoded data to server (%d)", err);
-#ifndef UNIX
- closeStream(x->x_lame);
-#else
lame_close( x->lgfp );
-#endif
x->x_lame = -1;
#ifndef UNIX
closesocket(x->x_fd);
@@ -344,21 +308,14 @@ static void mp3cast_dsp(t_mp3cast *x, t_signal **sp) /* initialize the lame library */
static void mp3cast_tilde_lame_init(t_mp3cast *x)
{
-#ifndef UNIX
- /* encoder related stuff (calculating buffer size) */
- BE_VERSION lameVersion = {0,}; /* version number of LAME */
- BE_CONFIG lameConfig = {0,}; /* config structure of LAME */
- unsigned int ret;
-#else
int ret;
x->lgfp = lame_init(); /* set default parameters for now */
-#endif
#ifndef UNIX
/* load lame_enc.dll library */
-
- dll=LoadLibrary("lame_enc.dll");
- if(dll==NULL)
+ HINSTANCE dll;
+ dll = LoadLibrary("lame_enc.dll");
+ if(!dll)
{
error("mp3cast~: error loading lame_enc.dll");
closesocket(x->x_fd);
@@ -367,75 +324,12 @@ static void mp3cast_tilde_lame_init(t_mp3cast *x) post("mp3cast~: connection closed");
return;
}
+#endif
- /* get Interface functions */
- initStream = (BEINITSTREAM) GetProcAddress(dll, TEXT_BEINITSTREAM);
- encodeChunk = (BEENCODECHUNK) GetProcAddress(dll, TEXT_BEENCODECHUNK);
- deinitStream = (BEDEINITSTREAM) GetProcAddress(dll, TEXT_BEDEINITSTREAM);
- closeStream = (BECLOSESTREAM) GetProcAddress(dll, TEXT_BECLOSESTREAM);
- dllVersion = (BEVERSION) GetProcAddress(dll, TEXT_BEVERSION);
- writeVBRHeader = (BEWRITEVBRHEADER) GetProcAddress(dll,TEXT_BEWRITEVBRHEADER);
-
- /* check if all interfaces are present */
- if(!initStream || !encodeChunk || !deinitStream || !closeStream || !dllVersion || !writeVBRHeader)
- {
-
- error("mp3cast~: unable to get LAME interfaces");
- closesocket(x->x_fd);
- x->x_fd = -1;
- outlet_float(x->x_obj.ob_outlet, 0);
- post("mp3cast~: connection closed");
- return;
- }
-
- /* get LAME version number */
- dllVersion(&lameVersion);
-
- post( "mp3cast~: lame_enc.dll version %u.%02u (%u/%u/%u)\n"
- " lame_enc engine %u.%02u",
- lameVersion.byDLLMajorVersion, lameVersion.byDLLMinorVersion,
- lameVersion.byDay, lameVersion.byMonth, lameVersion.wYear,
- lameVersion.byMajorVersion, lameVersion.byMinorVersion);
-
- memset(&lameConfig,0,sizeof(lameConfig)); /* clear all fields */
-#else
{
const char *lameVersion = get_lame_version();
post( "mp3cast~ : using lame version : %s", lameVersion );
}
-#endif
-
-#ifndef UNIX
-
- /* use the LAME config structure */
- lameConfig.dwConfig = BE_CONFIG_LAME;
-
- /* set the mpeg format flags */
- lameConfig.format.LHV1.dwStructVersion = 1;
- lameConfig.format.LHV1.dwStructSize = sizeof(lameConfig);
- lameConfig.format.LHV1.dwSampleRate = (int)sys_getsr(); /* input frequency - pd's sample rate */
- lameConfig.format.LHV1.dwReSampleRate = x->x_samplerate; /* output s/r - resample if necessary */
- lameConfig.format.LHV1.nMode = x->x_mp3mode; /* output mode */
- lameConfig.format.LHV1.dwBitrate = x->x_bitrate; /* mp3 bitrate */
- lameConfig.format.LHV1.nPreset = x->x_mp3quality; /* mp3 encoding quality */
- lameConfig.format.LHV1.dwMpegVersion = MPEG1; /* use MPEG1 */
- lameConfig.format.LHV1.dwPsyModel = 0; /* USE DEFAULT PSYCHOACOUSTIC MODEL */
- lameConfig.format.LHV1.dwEmphasis = 0; /* NO EMPHASIS TURNED ON */
- lameConfig.format.LHV1.bOriginal = TRUE; /* SET ORIGINAL FLAG */
- lameConfig.format.LHV1.bCopyright = TRUE; /* SET COPYRIGHT FLAG */
- lameConfig.format.LHV1.bNoRes = TRUE; /* no bit resorvoir */
-
- /* init the MP3 stream */
- ret = initStream(&lameConfig, &x->x_lamechunk, &x->x_mp3size, &x->x_lame);
-
- /* check result */
- if(ret != BE_ERR_SUCCESSFUL)
- {
- post("mp3cast~: error opening encoding stream (%lu)", ret);
- return;
- }
-
-#else
/* setting lame parameters */
lame_set_num_channels( x->lgfp, 2);
lame_set_in_samplerate( x->lgfp, sys_getsr() );
@@ -459,9 +353,6 @@ static void mp3cast_tilde_lame_init(t_mp3cast *x) post( "mp3cast~ : lame initialization done. (%d)", x->x_lame );
}
lame_init_bitstream( x->lgfp );
-#endif
-
-
}
/* connect to SHOUTcast server */
@@ -488,12 +379,7 @@ static void mp3cast_connect(t_mp3cast *x, t_symbol *hostname, t_floatarg fportno fd_set fdset;
struct timeval tv;
int sockfd;
-
-#ifndef UNIX
- unsigned int ret;
-#else
int ret;
-#endif
if(x->x_icecast == 0)portno++; /* use SHOUTcast, portno is one higher */
@@ -548,6 +434,7 @@ static void mp3cast_connect(t_mp3cast *x, t_symbol *hostname, t_floatarg fportno tv.tv_usec = 500; /* microseconds */
ret = select(sockfd + 1, &fdset, NULL, NULL, &tv);
+
if(ret < 0)
{
error("mp3cast~: can not read from socket");
@@ -558,18 +445,15 @@ static void mp3cast_connect(t_mp3cast *x, t_symbol *hostname, t_floatarg fportno #endif
return;
}
+#ifndef NT
ret = select(sockfd + 1, NULL, &fdset, NULL, &tv);
if(ret < 0)
{
error("mp3cast~: can not write to socket");
-#ifndef UNIX
- closesocket(sockfd);
-#else
close(sockfd);
-#endif
return;
}
-
+#endif
if(x->x_icecast == 0) /* SHOUTCAST */
{
/* now try to log in at SHOUTcast server */
@@ -717,23 +601,12 @@ static void mp3cast_disconnect(t_mp3cast *x) int err = -1;
if(x->x_lame >= 0)
{
-#ifndef UNIX
- /* deinit the stream */
- err = deinitStream(x->x_lame, x->x_mp3outbuf, &x->x_mp3size);
-
- /* check result */
- if(err != BE_ERR_SUCCESSFUL)
- {
- error("exiting mp3 stream failed (%lu)", err);
- }
- closeStream(x->x_lame); /* close mp3 encoder stream */
-#else
/* ignore remaining bytes */
if ( x->x_mp3size = lame_encode_flush( x->lgfp, x->x_mp3outbuf, 0) < 0 ) {
post( "mp3cast~ : warning : remaining encoded bytes" );
}
lame_close( x->lgfp );
-#endif
+
x->x_lame = -1;
post("mp3cast~: encoder stream closed");
}
@@ -800,11 +673,7 @@ static void mp3cast_print(t_mp3cast *x) }
post(" mode: %s\n"
" quality: %d", buf, x->x_mp3quality);
-#ifndef UNIX
- if(x->x_lamechunk!=0)post(" calculated mp3 chunk size: %d", x->x_lamechunk);
-#else
post(" mp3 chunk size: %d", x->x_lamechunk);
-#endif
if(x->x_samplerate!=sys_getsr())
{
post(" resampling from %d to %d Hz!", (int)sys_getsr(), x->x_samplerate);
@@ -851,11 +720,7 @@ static void mp3cast_name(t_mp3cast *x, t_symbol *name) static void mp3cast_free(t_mp3cast *x)
{
if(x->x_lame >= 0)
-#ifndef UNIX
- closeStream(x->x_lame);
-#else
- lame_close( x->lgfp );
-#endif
+ lame_close( x->lgfp );
if(x->x_fd >= 0)
#ifndef UNIX
closesocket(x->x_fd);
diff --git a/mp3live~/mp3fileout~.c b/mp3live~/mp3fileout~.c index 3782c7e..0559a75 100644 --- a/mp3live~/mp3fileout~.c +++ b/mp3live~/mp3fileout~.c @@ -47,18 +47,16 @@ #include <unistd.h> #include <fcntl.h> #include <stdio.h> -#include "mpg123.h" /* mpg123 decoding library from lame 3.92 */ -#include "mpglib.h" /* mpglib decoding library from lame 3.92 */ -#include "interface.h" /* mpglib decoding library from lame 3.92 */ #define SOCKET_ERROR -1 #else #include <winsock.h> +#include <io.h> +#include <fcntl.h> +#define MSG_NOSIGNAL 0 #endif - -#ifdef NT -#pragma warning( disable : 4244 ) -#pragma warning( disable : 4305 ) -#endif +#include "mpg123.h" /* mpg123 decoding library from lame 3.92 */ +#include "mpglib.h" /* mpglib decoding library from lame 3.92 */ +#include "interface.h" /* mpglib decoding library from lame 3.92 */ #define INPUT_BUFFER_SIZE 32768 #define OUTPUT_BUFFER_SIZE 32768 @@ -90,8 +88,9 @@ void mp3fileout_closesocket(int fd) #endif #ifdef NT closesocket(fd); -#endif +#else sys_rmpollfn(fd); +#endif } /* ------------------------ mp3fileout~ ----------------------------- */ @@ -390,6 +389,7 @@ static void mp3fileout_open(t_mp3fileout *x, t_symbol *filename) x->x_outframes = 0; outlet_float( x->x_frames, x->x_outframes ); } + if ( ( x->x_fd = open( filename->s_name, O_RDONLY ) ) < 0 ) { post( "mp3fileout~ : could not open file : %s", filename->s_name ); diff --git a/mp3live~/mp3streamin~.c b/mp3live~/mp3streamin~.c index 0d88096..74a11f4 100644 --- a/mp3live~/mp3streamin~.c +++ b/mp3live~/mp3streamin~.c @@ -51,18 +51,15 @@ #include <unistd.h> #include <fcntl.h> #include <stdio.h> -#include "mpg123.h" /* mpg123 decoding library from lame 3.92 */ -#include "mpglib.h" /* mpglib decoding library from lame 3.92 */ -#include "interface.h" /* mpglib decoding library from lame 3.92 */ #define SOCKET_ERROR -1 #else #include <winsock.h> +#define MSG_NOSIGNAL 0 +#define SOL_TCP IPPROTO_TCP #endif - -#ifdef NT -#pragma warning( disable : 4244 ) -#pragma warning( disable : 4305 ) -#endif +#include "mpg123.h" /* mpg123 decoding library from lame 3.92 */ +#include "mpglib.h" /* mpglib decoding library from lame 3.92 */ +#include "interface.h" /* mpglib decoding library from lame 3.92 */ #define MIN_AUDIO_INPUT 8064 // we must a least have 8 chunks to play a correct sound #define INPUT_BUFFER_SIZE MIN_AUDIO_INPUT diff --git a/mp3live~/mp3streamout~.c b/mp3live~/mp3streamout~.c index 414af92..8208f38 100644 --- a/mp3live~/mp3streamout~.c +++ b/mp3live~/mp3streamout~.c @@ -29,13 +29,6 @@ /* Theo Hakola -- */ /* ---------------------------------------------------------------------------- */ - - -#ifdef NT -#pragma warning( disable : 4244 ) -#pragma warning( disable : 4305 ) -#endif - #include <sys/types.h> #include <string.h> #include <stdio.h> @@ -54,15 +47,15 @@ #include <netdb.h> #include <time.h> #include <sys/time.h> -#include <lame/lame.h> /* lame encoder stuff */ #define SOCKET_ERROR -1 #else #include <io.h> #include <windows.h> #include <winsock.h> #include <windef.h> -#include "lame_enc.h" /* lame encoder stuff */ +#define MSG_NOSIGNAL 0 #endif +#include <lame/lame.h> /* lame encoder stuff */ #include "m_pd.h" /* standard pd stuff */ @@ -81,16 +74,6 @@ extern int head_check( unsigned long head, int check_layer ); static char *mp3streamout_version = "mp3streamout~: mp3 peer-to-peer streamer version 0.3, written by ydegoyon@free.fr"; -#ifndef UNIX -static HINSTANCE dll = NULL; -static BEINITSTREAM initStream = NULL; -static BEENCODECHUNK encodeChunk = NULL; -static BEDEINITSTREAM deinitStream = NULL; -static BECLOSESTREAM closeStream = NULL; -static BEVERSION dllVersion = NULL; -static BEWRITEVBRHEADER writeVBRHeader = NULL; -#endif - static t_class *mp3streamout_class; typedef struct _mp3streamout @@ -123,9 +106,7 @@ typedef struct _mp3streamout t_float x_f; /* float needed for signal input */ -#ifdef UNIX lame_global_flags* lgfp; -#endif } t_mp3streamout; @@ -190,28 +171,18 @@ static void mp3streamout_encode(t_mp3streamout *x) } /* encode mp3 data */ -#ifndef UNIX - err = encodeChunk(x->x_lame, x->x_lamechunk, x->x_mp3inbuf, x->x_mp3outbuf, &x->x_mp3size); -#else + x->x_mp3size = lame_encode_buffer_interleaved(x->lgfp, x->x_mp3inbuf, x->x_lamechunk/lame_get_num_channels(x->lgfp), x->x_mp3outbuf, MY_MP3_MALLOC_OUT_SIZE); x->x_mp3size+=lame_encode_flush( x->lgfp, x->x_mp3outbuf+x->x_mp3size, MY_MP3_MALLOC_OUT_SIZE-x->x_mp3size ); // post( "mp3streamout~ : encoding returned %d frames", x->x_mp3size ); -#endif /* check result */ -#ifndef UNIX - if(err != BE_ERR_SUCCESSFUL) - { - closeStream(x->x_lame); - error("mp3streamout~: lameEncodeChunk() failed (%lu)", err); -#else if(x->x_mp3size<0) { lame_close( x->lgfp ); error("mp3streamout~: lame_encode_buffer_interleaved failed (%d)", x->x_mp3size); -#endif x->x_lame = -1; } } @@ -237,11 +208,7 @@ static void mp3streamout_stream(t_mp3streamout *x) if(count < 0) { error("mp3streamout~: could not send encoded data to the peer (%d)", count); -#ifndef UNIX - closeStream(x->x_lame); -#else lame_close( x->lgfp ); -#endif x->x_lame = -1; #ifndef UNIX closesocket(x->x_fd); @@ -368,19 +335,12 @@ static void mp3streamout_dsp(t_mp3streamout *x, t_signal **sp) /* initialize the lame library */ static void mp3streamout_tilde_lame_init(t_mp3streamout *x) { -#ifndef UNIX - /* encoder related stuff (calculating buffer size) */ - BE_VERSION lameVersion = {0,}; /* version number of LAME */ - BE_CONFIG lameConfig = {0,}; /* config structure of LAME */ - unsigned int ret; -#else int ret; x->lgfp = lame_init(); /* set default parameters for now */ -#endif #ifndef UNIX /* load lame_enc.dll library */ - + HINSTANCE dll; dll=LoadLibrary("lame_enc.dll"); if(dll==NULL) { @@ -391,75 +351,12 @@ static void mp3streamout_tilde_lame_init(t_mp3streamout *x) post("mp3streamout~: connection closed"); return; } - - /* get Interface functions */ - initStream = (BEINITSTREAM) GetProcAddress(dll, TEXT_BEINITSTREAM); - encodeChunk = (BEENCODECHUNK) GetProcAddress(dll, TEXT_BEENCODECHUNK); - deinitStream = (BEDEINITSTREAM) GetProcAddress(dll, TEXT_BEDEINITSTREAM); - closeStream = (BECLOSESTREAM) GetProcAddress(dll, TEXT_BECLOSESTREAM); - dllVersion = (BEVERSION) GetProcAddress(dll, TEXT_BEVERSION); - writeVBRHeader = (BEWRITEVBRHEADER) GetProcAddress(dll,TEXT_BEWRITEVBRHEADER); - - /* check if all interfaces are present */ - if(!initStream || !encodeChunk || !deinitStream || !closeStream || !dllVersion || !writeVBRHeader) - { - - error("mp3streamout~: unable to get LAME interfaces"); - closesocket(x->x_fd); - x->x_fd = -1; - outlet_float(x->x_obj.ob_outlet, 0); - post("mp3streamout~: connection closed"); - return; - } - - /* get LAME version number */ - dllVersion(&lameVersion); - - post( "mp3streamout~: lame_enc.dll version %u.%02u (%u/%u/%u)\n" - " lame_enc engine %u.%02u", - lameVersion.byDLLMajorVersion, lameVersion.byDLLMinorVersion, - lameVersion.byDay, lameVersion.byMonth, lameVersion.wYear, - lameVersion.byMajorVersion, lameVersion.byMinorVersion); - - memset(&lameConfig,0,sizeof(lameConfig)); /* clear all fields */ -#else +#endif { const char *lameVersion = get_lame_version(); post( "mp3streamout~ : using lame version : %s", lameVersion ); } -#endif - -#ifndef UNIX - - /* use the LAME config structure */ - lameConfig.dwConfig = BE_CONFIG_LAME; - - /* set the mpeg format flags */ - lameConfig.format.LHV1.dwStructVersion = 1; - lameConfig.format.LHV1.dwStructSize = sizeof(lameConfig); - lameConfig.format.LHV1.dwSampleRate = (int)sys_getsr(); /* input frequency - pd's sample rate */ - lameConfig.format.LHV1.dwReSampleRate = x->x_samplerate; /* output s/r - resample if necessary */ - lameConfig.format.LHV1.nMode = x->x_mp3mode; /* output mode */ - lameConfig.format.LHV1.dwBitrate = x->x_bitrate; /* mp3 bitrate */ - lameConfig.format.LHV1.nPreset = x->x_mp3quality; /* mp3 encoding quality */ - lameConfig.format.LHV1.dwMpegVersion = MPEG1; /* use MPEG1 */ - lameConfig.format.LHV1.dwPsyModel = 0; /* USE DEFAULT PSYCHOACOUSTIC MODEL */ - lameConfig.format.LHV1.dwEmphasis = 0; /* NO EMPHASIS TURNED ON */ - lameConfig.format.LHV1.bOriginal = TRUE; /* SET ORIGINAL FLAG */ - lameConfig.format.LHV1.bCopyright = TRUE; /* SET COPYRIGHT FLAG */ - lameConfig.format.LHV1.bNoRes = TRUE; /* no bit resorvoir */ - - /* init the MP3 stream */ - ret = initStream(&lameConfig, &x->x_lamechunk, &x->x_mp3size, &x->x_lame); - - /* check result */ - if(ret != BE_ERR_SUCCESSFUL) - { - post("mp3streamout~: error opening encoding stream (%lu)", ret); - return; - } -#else /* setting lame parameters */ lame_set_num_channels( x->lgfp, 2); lame_set_in_samplerate( x->lgfp, sys_getsr() ); @@ -483,9 +380,6 @@ static void mp3streamout_tilde_lame_init(t_mp3streamout *x) post( "mp3streamout~ : lame initialization done. (%d)", x->x_lame ); } lame_init_bitstream( x->lgfp ); -#endif - - } /* connect to the peer */ @@ -567,23 +461,11 @@ static void mp3streamout_disconnect(t_mp3streamout *x) int err = -1; if(x->x_lame >= 0) { -#ifndef UNIX - /* deinit the stream */ - err = deinitStream(x->x_lame, x->x_mp3outbuf, &x->x_mp3size); - - /* check result */ - if(err != BE_ERR_SUCCESSFUL) - { - error("exiting mp3 stream failed (%lu)", err); - } - closeStream(x->x_lame); /* close mp3 encoder stream */ -#else /* ignore remaining bytes */ if ( x->x_mp3size = lame_encode_flush( x->lgfp, x->x_mp3outbuf, 0) < 0 ) { post( "mp3streamout~ : warning : remaining encoded bytes" ); } lame_close( x->lgfp ); -#endif x->x_lame = -1; post("mp3streamout~: encoder stream closed"); } @@ -676,11 +558,8 @@ static void mp3streamout_free(t_mp3streamout *x) { if(x->x_lame >= 0) -#ifndef UNIX - closeStream(x->x_lame); -#else lame_close( x->lgfp ); -#endif + if(x->x_fd >= 0) #ifndef UNIX closesocket(x->x_fd); diff --git a/mp3write~/mp3write~.c b/mp3write~/mp3write~.c index e3afe7c..ea42040 100644 --- a/mp3write~/mp3write~.c +++ b/mp3write~/mp3write~.c @@ -29,13 +29,6 @@ /* Gang Of Four - "Guns Before Butter" */
/* ---------------------------------------------------------------------------- */
-
-
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-
#include <string.h>
#include <stdio.h>
#include <errno.h>
@@ -54,16 +47,14 @@ #include <netdb.h>
#include <time.h>
#include <sys/time.h>
-#include <lame/lame.h> /* lame encoder stuff */
#define SOCKET_ERROR -1
#else
#include <io.h>
#include <windows.h>
#include <winsock.h>
#include <windef.h>
-#include "lame_enc.h" /* lame encoder stuff */
#endif
-
+#include <lame/lame.h> /* lame encoder stuff */
#include "m_pd.h" /* standard pd stuff */
#define MY_MP3_MALLOC_IN_SIZE 65536
@@ -76,17 +67,6 @@ static char *mp3write_version = "mp3write~: mp3 file recorder version 0.4, written by Yves Degoyon";
static int sockfd;
-#ifndef UNIX
-static HINSTANCE dll = NULL;
-static BEINITSTREAM initStream = NULL;
-static BEENCODECHUNK encodeChunk = NULL;
-static BEDEINITSTREAM deinitStream = NULL;
-static BECLOSESTREAM closeStream = NULL;
-static BEVERSION dllVersion = NULL;
-static BEWRITEVBRHEADER writeVBRHeader = NULL;
-#endif
-
-
static t_class *mp3write_class;
typedef struct _mp3write
@@ -122,9 +102,7 @@ typedef struct _mp3write t_float x_f; /* float needed for signal input */
char *x_title; /* title of the mp3 */
-#ifdef UNIX
lame_global_flags *lgfp; /* lame encoder configuration */
-#endif
} t_mp3write;
@@ -189,27 +167,17 @@ static void mp3write_encode(t_mp3write *x) }
/* encode mp3 data */
-#ifndef UNIX
- err = encodeChunk(x->x_lame, x->x_lamechunk, x->x_mp3inbuf, x->x_mp3outbuf, &x->x_mp3size);
-#else
+
x->x_mp3size = lame_encode_buffer_interleaved(x->lgfp, x->x_mp3inbuf,
x->x_lamechunk/lame_get_num_channels(x->lgfp),
x->x_mp3outbuf, MY_MP3_MALLOC_OUT_SIZE);
// post( "mp3write~ : encoding returned %d frames", x->x_mp3size );
-#endif
/* check result */
-#ifndef UNIX
- if(err != BE_ERR_SUCCESSFUL)
- {
- closeStream(x->x_lame);
- error("mp3write~: lameEncodeChunk() failed (%lu)", err);
-#else
if(x->x_mp3size<0)
{
lame_close( x->lgfp );
error("mp3write~: lame_encode_buffer_interleaved failed (%d)", x->x_mp3size);
-#endif
x->x_lame = -1;
}
}
@@ -233,11 +201,7 @@ static void mp3write_writeframes(t_mp3write *x) if(err < 0)
{
error("mp3write~: could not write encoded data to file (%d)", err);
-#ifndef UNIX
- closeStream(x->x_lame);
-#else
lame_close( x->lgfp );
-#endif
x->x_lame = -1;
#ifndef UNIX
error("mp3write~: writing data");
@@ -361,19 +325,12 @@ static int mp3write_tilde_lame_init(t_mp3write *x) {
time_t now;
-#ifndef UNIX
- /* encoder related stuff (calculating buffer size) */
- BE_VERSION lameVersion = {0,}; /* version number of LAME */
- BE_CONFIG lameConfig = {0,}; /* config structure of LAME */
- unsigned int ret;
-#else
int ret;
x->lgfp = lame_init(); /* set default parameters for now */
-#endif
#ifndef UNIX
/* load lame_enc.dll library */
-
+ HINSTANCE dll;
dll=LoadLibrary("lame_enc.dll");
if(dll==NULL)
{
@@ -383,74 +340,12 @@ static int mp3write_tilde_lame_init(t_mp3write *x) post("mp3write~: connection closed");
return -1;
}
-
- /* get Interface functions */
- initStream = (BEINITSTREAM) GetProcAddress(dll, TEXT_BEINITSTREAM);
- encodeChunk = (BEENCODECHUNK) GetProcAddress(dll, TEXT_BEENCODECHUNK);
- deinitStream = (BEDEINITSTREAM) GetProcAddress(dll, TEXT_BEDEINITSTREAM);
- closeStream = (BECLOSESTREAM) GetProcAddress(dll, TEXT_BECLOSESTREAM);
- dllVersion = (BEVERSION) GetProcAddress(dll, TEXT_BEVERSION);
- writeVBRHeader = (BEWRITEVBRHEADER) GetProcAddress(dll,TEXT_BEWRITEVBRHEADER);
-
- /* check if all interfaces are present */
- if(!initStream || !encodeChunk || !deinitStream || !closeStream || !dllVersion || !writeVBRHeader)
- {
-
- error("mp3write~: unable to get LAME interfaces");
- closesocket(x->x_fd);
- x->x_fd = -1;
- post("mp3write~: connection closed");
- return -1;
- }
-
- /* get LAME version number */
- dllVersion(&lameVersion);
-
- post( "mp3write~: lame_enc.dll version %u.%02u (%u/%u/%u)\n"
- " lame_enc engine %u.%02u",
- lameVersion.byDLLMajorVersion, lameVersion.byDLLMinorVersion,
- lameVersion.byDay, lameVersion.byMonth, lameVersion.wYear,
- lameVersion.byMajorVersion, lameVersion.byMinorVersion);
-
- memset(&lameConfig,0,sizeof(lameConfig)); /* clear all fields */
-#else
+#endif
{
const char *lameVersion = get_lame_version();
post( "mp3write~ : using lame version : %s", lameVersion );
}
-#endif
-
-#ifndef UNIX
- /* use the LAME config structure */
- lameConfig.dwConfig = BE_CONFIG_LAME;
-
- /* set the mpeg format flags */
- lameConfig.format.LHV1.dwStructVersion = 1;
- lameConfig.format.LHV1.dwStructSize = sizeof(lameConfig);
- lameConfig.format.LHV1.dwSampleRate = (int)sys_getsr(); /* input frequency - pd's sample rate */
- lameConfig.format.LHV1.dwReSampleRate = x->x_samplerate; /* output s/r - resample if necessary */
- lameConfig.format.LHV1.nMode = x->x_mp3mode; /* output mode */
- lameConfig.format.LHV1.dwBitrate = x->x_bitrate; /* mp3 bitrate */
- lameConfig.format.LHV1.nPreset = x->x_mp3quality; /* mp3 encoding quality */
- lameConfig.format.LHV1.dwMpegVersion = MPEG1; /* use MPEG1 */
- lameConfig.format.LHV1.dwPsyModel = 0; /* USE DEFAULT PSYCHOACOUSTIC MODEL */
- lameConfig.format.LHV1.dwEmphasis = 0; /* NO EMPHASIS TURNED ON */
- lameConfig.format.LHV1.bOriginal = TRUE; /* SET ORIGINAL FLAG */
- lameConfig.format.LHV1.bCopyright = TRUE; /* SET COPYRIGHT FLAG */
- lameConfig.format.LHV1.bNoRes = TRUE; /* no bit resorvoir */
-
- /* init the MP3 stream */
- ret = initStream(&lameConfig, &x->x_lamechunk, &x->x_mp3size, &x->x_lame);
-
- /* check result */
- if(ret != BE_ERR_SUCCESSFUL)
- {
- post("mp3write~: error opening encoding stream (%lu)", ret);
- return -1;
- }
-
-#else
/* setting lame parameters */
lame_set_num_channels( x->lgfp, 2);
lame_set_in_samplerate( x->lgfp, sys_getsr() );
@@ -485,7 +380,6 @@ static int mp3write_tilde_lame_init(t_mp3write *x) sprintf( x->x_title, "Started at %s", ctime(&now) );
id3tag_set_title(x->lgfp, x->x_title );
-#endif
return 0;
}
@@ -638,11 +532,7 @@ static void mp3write_stop(t_mp3write *x) x->x_recflag = 0;
/* flushing remaining frames and tag */
-#ifndef UNIX
- deinitStream(x->x_lame, x->x_mp3outbuf, &x->x_mp3size);
-#else
x->x_mp3size = lame_encode_flush( x->lgfp, x->x_mp3outbuf, MY_MP3_MALLOC_OUT_SIZE );
-#endif
mp3write_writeframes(x); /* write mp3 to file */
@@ -654,11 +544,7 @@ static void mp3write_stop(t_mp3write *x) static void mp3write_free(t_mp3write *x)
{
if(x->x_lame >= 0)
-#ifndef UNIX
- closeStream(x->x_lame);
-#else
lame_close( x->lgfp );
-#endif
if(x->x_fd >= 0)
#ifndef UNIX
_close(x->x_fd);
|