I have programs that convert a WAV file to MP3, but when I have to send over the internet every second, and every time to make a WAV file for only one second and then convert to another file MP3, it too much processing, too many files, and too slow....
I want to give to a DLL(let say), a pointer to the WAV data, the DLL converts the data to MP3 and returns a pointer to the new buffer, then I can send the buffer over the internet to the person I'm chatting with.... (and there the reverse is done)
Maybe there are OCX, or DLL files that do ALL that, but I want only the converting part because I want to throw in an encription algoritm before sending the data (I know how to do that)
All I need is something that convers to mp3 and vice versa in memory....
It's a DLL, as I was hoping, It's called BladeEnc.DLL (Blade Encoder DLL). BUT it works only in C/C++, I don't know why it does not work in Visual Basic... (I could not get it to work...)
But I got around it, of course, I made another DLL, in MFC that is using the BladeEnc.DLL, and this one can be included in Visual Basic.
I attached my source code for the DLL(that uses BladeEnc.DLL), a BAS file so you can use my DLL in Visual Basic, and a CLS, to make your life a little easier . The code is not very good, but it's a start
So, let's recap.
The CLS uses the BAS, the BAS uses the BladeEncVB.DLL, and BladeEncVB.DLL uses the BladeEnc.DLL....
If your wandering if it affects the speed passing values from one to the other, then the other, and so on.... I say ... NO, not really... If you notice, every time it's passing pointers (4 Bytes for each parameter), so, that should not slow down the encoding part even if the buffer is very long, it only passes 4 bytes (it's pointer)
Also, you will notice a new function I made, ChangeSoundVolume and ChangeSoundVolumeB, both of them are for 16 Bit WAV buffer, just the way you pass the data is different. Visual Basic is slow on loops, that's why I made it in the BladeEncVB.DLL
OK, NOW !
I have another problem
ANYONE find the same thing but to DECODE !
(To decode in memory like this DLL...)
PS: I noticed this thread has top rating, I wander how it will be after this post
If anyone makes improvements to my code, please post the code here, Thanks...
Thank you for your Dll. I will try it as soon as possible.
I don't know C/C++, but i see you do so have a look at this file, maybe it can help you.
I've got other files that could help but bigger than 100 Ko. Can you send me your email please cause i don't remember where i download them.
I have a mp3 encoding example on my website. I didn't make the dll so I don't know if it encodes in memory or not. Couldn't hurt to try it out I guess. I saw a couple examples at planetsourcecode using a c++ dll to decode a mp3 to a wave file. Again I don't know if it does it in memory or not.
The Dll you've made is just great. It works well, I can code in mp3. Only one thing, I don't know why, but i can't get access to your event MP3buffer(Buffer() as byte). One other thing is that i don't know why when outputing to a file the end of the file is just no sound but what i encoded is perfect. (I recorded 8s via DSound8 : 8s perfect then 8s nosound).
Thank you for all
Hope you'll find the other way (mp3->wav).
' General Declarations...
Private WithEvents BEncoder As BladeEncoder
Private Sub Form_Load()
Set BEncoder = New BladeEncoder
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Set BEncoder = Nothing
End Sub
And to fix the problem with the second buffer not being correct you need to make the DirectX buffer a multiple of BEncoder.Samples and to make sure the buffer is aligned (divizible by 4)
Code:
Private Sub DirectXEvent8_DXCallback(ByVal eventid As Long)
Dim DataBuff() As Byte
ReDim DataBuff(HBuffer - 1)
Select Case eventid
Case StartEvent
gDSCB.ReadBuffer HBuffer, HBuffer, DataBuff(0), DSCBLOCK_DEFAULT
Case MidEvent
gDSCB.ReadBuffer 0, HBuffer, DataBuff(0), DSCBLOCK_DEFAULT
Case EndEvent
BEncoder.CloseStream
End Select
If eventid = StartEvent Or eventid = MidEvent Then
' write to file...
End If
End Sub
' when you initialize your DirectX sound do this
Private Sub Initialize()
... declarations.....
' you must call BEncoder.InitStream before this line
HBuffer = BEncoder.Samples * 8
HBuffer = HBuffer + (HBuffer Mod wFormat.nBlockAlign)
BufferSize = HBuffer * 2
With dscBuf
.fxFormat = wFormat
.lBufferBytes = BufferSize
.lFlags = DSCBCAPS_DEFAULT
End With
Set gDSCB = gDSC.CreateCaptureBuffer(dscBuf)
ReDim dsbpn(0 To 2) As DSBPOSITIONNOTIFY
StartEvent = gDX.CreateEvent(Me)
With dsbpn(0)
.hEventNotify = StartEvent
.lOffset = 1
End With
MidEvent = gDX.CreateEvent(Me)
With dsbpn(1)
.hEventNotify = MidEvent
.lOffset = HBuffer
End With
EndEvent = gDX.CreateEvent(Me)
With dsbpn(2)
.hEventNotify = EndEvent
.lOffset = DSBPN_OFFSETSTOP
End With
gDSCB.SetNotificationPositions 3, dsbpn()
gDSCB.Start DSCBSTART_LOOPING
End Sub
I would want to share the program i'm working on (SoundBroadcast), but I don't really want to share the code at this point, it's too messy... lot's of functions that are not used... it's not comented at all.... (I hate that ), I don't need coments for myself...
The initial code was only for recording sound to a wave file, and I modified the project to compress to mp3, then to send to whomever is connected to the program...
But the program itself (compiled) is pretty good....
It's basicly like a Shouthcast server.... except this one is sending what you curently have on you sound card... if windows makes a sound, or if ICQ is on, or something like that... the people connected hear whatever you hear on your sound card hehe, and oviously, if the micrphone is on, you can also talk in it, and they will hear it.... (That's how I really wanted to do), then I discovered that it works for all sounds....
Well... I think it depends on the sound card also.... with mine i can set it to "what you hear", or a specific input... like wave, midi, mic., etc.
Anyways....
If you want to put the Setup program on your web-page, just tell me, and i'll make the setup, and i'll put it on MY web-page (probaly it's about 3 - 4 Megs) so you can download it.... (I don't have any hits on my web-page...)
I found another dll that works for encoding like bladeenc.dll.
It's lame_enc.dll
you can find it there : http://www.jthz.com/~lame/
It uses the same functions that bladeenc.dll so I just rebuild your C/C++ project changing the name of the library to load.
I think the sound quality is better.
I'm trying for days to get the mpglib.dll to work, but it crashes everytime I try to decode.... I think the DLL is accessing memory outside of the array I pass it to....
Well.... if anyone finds a DLL to decode for MP3, even if it's in C/C++, please post a message where i can get it from.... I will write the code so it can be used in VB.....
I wanted to make a DLL for both Encode and Decode, but the decode crashes when I use the function DecDecodeChunk (decodeMP3 in DLL). It does not crash the first time I call it, but after 2 to 5 calls.... I named the functions (for VB) different so there is an obvious distinction between encode functions, and decode functions...
I have Windows 2000, so my windows does not crash, but if you have Windows 98, 95 I think it will crash windows too...
From mpglibdll.h
WARNING: If decodeMP3 returns MP3_ERR you should instantly reinitialize the mpglib. Otherwise it could crash. Originally the mpglib exits if a heavy error occurs. This is disabled in the mpglib.dll (#define BE_QUIET) to force playback of corrupted MP3 files.
I don't really like the sound of that....
When I try to decode, the decodeMP3 function returns MP3_ERR every time after the first call....
By the way.... the Lame Encoder.... I looked on the net for example code in C/C++, and I could not find any, but I looked in the DLL, and it has a couple more functions, and it seems that it can do more than just encoding.... but not sure since I don't any samples how to use it....
I'm thinking to add in InitializeEncodeDLL a parameter to what DLL you want to use. I did not do that yet, since I don't know for sure how to use it.
Last edited by CVMichael; May 16th, 2002 at 02:57 AM.
If you want I have a nice mp3 encoder someone made in vb that uses the lame dll. I don't remember his name but I downloaded it from planet source code. I don't know if it is still their or not. LMK and I could put it on my webpage and give you a link to download it from.
I've looked over the net for days, and nothing.... most of the decode DLLs i found I can't get them to work.... lots and lots of errors and crashes.... and all kinds of weird stuff
And mpglib.dll, I still did not get it to work... keeps crashing my VB
You were saying that you are gonna look at my attempts to make it work..... Did you had any success ?
Last edited by CVMichael; May 16th, 2002 at 02:55 AM.
Have a loof at www.fmod.org. I'm sure something can be done with tis dll.
I didn't look so far at the moment. So, I don't know how it works, I've just look the examples in VB. They don't use in memory translation but I'm sure this can be done.