CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: MP3 into stream

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Location
    Greece
    Posts
    2

    MP3 into stream

    Hey.

    I am doing some experiments for my own entertainment. I want to break an .mp3 file into smaller files. I found some pieces of codes arround to get an idea and so i wrote:

    myFs = new FileStream( "TestTrack.mp3", FileMode.Open, FileAccess.Read );
    Byte[] MyByteArray = new Byte[128000];
    myFs.Read (MyByteArray, 0, MyByteArray.Length);

    then i save this stream to a file "tempfile.mp3".

    As it is there, tempfile.mp3 is an exact copy of the original file "TestTrack.mp3"

    The aim is to save only some bytes of the original file in a stream or something and save it as an .mp3 file and then play it.


    But why all that? I am planing to write an application, that records Line-In signal from my soundcard as a wav or mp3 file, then using buffers send the streams to a client or server program using sockets , which will read the stream and play it while receiving the next one.

    So i am at the moment playing arround with small pieces of code to make sure that i fully understand what i am doing.

    I will greatly appreciate your help and i'll be happy to share my complete code with u when its finished as there is nothing realy neat arround such an application on the net for amateur programmers.

  2. #2
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    Re: MP3 into stream

    A few things that come to mind:

    You might look into the LAME mp3 encoding library: http://lame.sourceforge.net/. It's pretty solid. Long story short, mp3 encoding is a little complicated. By the way, why are you trying to delete bytes from an mp3? It's not really that simple (you can't just drop bytes and expect victory) and it's already a highly compressed audio format... What's your goal here?

    Also, before you embark, you might take a look at VLC Media Player. I'm fairly certain it can do some of the streaming functions you are interested in... (not sure; I was thinking about this awhile ago). Not sure about compression across the network (but I assume it's enabled; you'll have to look).

    Although it does not support streaming output (as near as I can tell anyway), you might also find Audacity (an audio editor) a useful development tool: http://audacity.sourceforge.net/
    Last edited by BioPhysEngr; June 15th, 2011 at 12:37 AM. Reason: fix typo
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Join Date
    Apr 2011
    Location
    Greece
    Posts
    2

    Re: MP3 into stream

    Thanks for your reply,

    I did have a look at VLC player , it would realy save the day but from what i saw it doesnt transmit real by capturing Line-In, it can only stream a file in a playlist.

    If i delete bytes from the .mp3, i do it by accident probably cuz i dont fully understand the code i typed there. My aim is to store the first quarter of the file in a byte array and send it using sockets to the other side.

    For now am just playign arround to see how to do break the mp3 file into streams and then play the streams. Without envolving sockets or real-time audio encoding for now.

    Could someone post any changes on my code that does that? or any examples?

    thanks in advance

  4. #4
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    Re: MP3 into stream

    I think VLC should be able to support this; see e.g. http://forum.videolan.org/viewtopic.php?f=13&t=91250

    Not sure; I'll try to look at it this evening.
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  5. #5
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    Re: MP3 into stream

    So I played around with VLC this evening (version 1.1.4) and found that I could successfully stream live audio captured from my webcam microphone (this is slightly different from line in, but I think it's only a tiny detail) across the home network. There was about a 1 second delay using a 802.11g connection (and little other traffic on the network).

    Did it like this:

    On the source computer:
    (1) Went to Media > Open Capture Device
    (2) Selected my webcam's microphone from the dropdown for Audio Device Name; Set video device to "None"
    (3) Clicked on the arrow next to 'Play' at the bottom and selected "Stream"
    (4) New dialog box opened
    (5) Left source as the default (dshow://) and clicked next
    (6) Set new destination to HTTP and clicked add
    (7) New tab opened to set HTTP settings: left port at default (8080)
    (8) Clicked 'activate transcoding' and selecting mp3 from the dropdown box
    (9) Clicked Stream

    Then, on the receiving computer:
    (10) Clicked Media > Open Network Stream
    (11) Typed in my computer's IP address on the subnet and specified port 8080 (that is typed in:
    http://192.168.1.2:8080 where 192.168.1.2 is the source computer frmo the first part)
    (12) Clicked play
    (13) Victory!

    Anyway, try it to see if it works for you!

    I see where you are going with breaking them into pieces; sorry for not understanding previously. If you want to pursue it further, that's fine of course, but I'm not familiar enough with how mp3 encoding works to advise you much. Mostly my advice is: if you want to have learn and enjoy doing it, keep writing the software. Otherwise, just go with the utilitarian ready-made solution from VLC.
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured