Streaming audio

Hi,

I have been searching in google and here in the forums, but I still don’t know which is the way to stream audio from internet. What I’m trying to do so far is just to stream a wav file (if it’s easier with ogg I can change, that’s not a problem), I mean, open it from a http URL and play it.

I don’t know if I have to use SDL, SDL_Mixer, a combination of them or maybe some of the other libraries based on SDL. I have been trying to use different functions like SDL_RWFromFP, SDL_LoadWAV_RW or Mix_LoadMUS, with no luck, so I’m sure I am missing something. I hope somebody can give me the clue to achieve my goal.

Thank you in advance.

Looks like you’re trying to treat this as one problem, when it’s actually two.? You need to be able to do two separate things, download a file and play a song from a stream, and then combine them.

The various SDL music-playing functions only know how to play files from streams.? (And a few helper functions to load a local file from disc into a stream, so they can play from the stream.)? But when it comes down to it, a SDL_RWops is a stream interface, and you can wrap one around any object from any language that implements the basic stream operations.

So what you need now is to figure out how to open an HTTP connection to your music location and get back a download stream.? Exactly how that’s done depends on what language and what Internet framework you’re using, but you should be able to figure it out with a bit of research.? Once you’ve got that, just wrap your stream in an SDL_RWops and feed it to SDL.

…except that under some circumstances (I forget exactly which) the SDL code will want to read the entire song into memory all at once instead of playing it continually from the stream.? This is obviously designed for local files and won’t work for streaming audio from the Internet.? So keep that in mind and if it becomes a problem, you’ll have to look into it and maybe ask some questions here.? But first things first, figure out how to get an HTTP stream.

Mason________________________________
From: hmartinez <hector.martinez at sensetrix.com>
To: sdl at lists.libsdl.org
Sent: Monday, May 28, 2012 10:40 PM
Subject: [SDL] Streaming audio

Hi,

I have been searching in google and here in the forums, but I still don’t know which is the way to stream audio from internet. What I’m trying to do so far is just to stream a wav file (if it’s easier with ogg I can change, that’s not a problem), I mean, open it from a http URL and play it.

I don’t know if I have to use SDL, SDL_Mixer, a combination of them or maybe some of the other libraries based on SDL. I have been trying to use different functions like SDL_RWFromFP, SDL_LoadWAV_RW or Mix_LoadMUS, with no luck, so I’m sure I am missing something. I hope somebody can give me the clue to achieve my goal.

Thank you in advance.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Mason Wheeler wrote:

Looks like you’re trying to treat this as one problem, when it’s actually two. You need to be able to do two separate things, download a file and play a song from a stream, and then combine them.

The various SDL music-playing functions only know how to play files from streams. (And a few helper functions to load a local file from disc into a stream, so they can play from the stream.) But when it comes down to it, a SDL_RWops is a stream interface, and you can wrap one around any object from any language that implements the basic stream operations.

So what you need now is to figure out how to open an HTTP connection to your music location and get back a download stream. Exactly how that’s done depends on what language and what Internet framework you’re using, but you should be able to figure it out with a bit of research. Once you’ve got that, just wrap your stream in an SDL_RWops and feed it to SDL.

…except that under some circumstances (I forget exactly which) the SDL code will want to read the entire song into memory all at once instead of playing it continually from the stream. This is obviously designed for local files and won’t work for streaming audio from the Internet. So keep that in mind and if it becomes a problem, you’ll have to look into it and maybe ask some questions here. But first things first, figure out how to get an HTTP stream.

Mason

Hi Mason, thank you for your answer.

In fact, when I was trying to use SDL_RWops, I was trying to do as you say in your message. As it needs a FILE object as first argument, I was trying to feed it with a FILE that was being updated with ‘fread’ function, but with no luck (I mean, I wasn’t able to get the stream). That’s why I was wondering that maybe somebody could help me in getting the stream, because I thought it should be easy to do.

I am using c++ and the internet file I want to stream is just a normal one that you can find in any webpage (I mean http://…/audio.wav).

It only needs a FILE if you call SDL_RWFromFP.? But if you call SDL_AllocRW instead, and then set the members manually, you can wrap it around a stream easily enough.________________________________
From: hmartinez <hector.martinez at sensetrix.com>
To: sdl at lists.libsdl.org
Sent: Tuesday, May 29, 2012 11:07 PM
Subject: Re: [SDL] Streaming audio

Mason Wheeler wrote:
Looks like you’re trying to treat this as one problem, when it’s actually two. You need to be able to do two separate things, download a file and play a song from a stream, and then combine them.

The various SDL music-playing functions only know how to play files from streams. (And a few helper functions to load a local file from disc into a stream, so they can play from the stream.) But when it comes down to it, a SDL_RWops is a stream interface, and you can wrap one around any object from any language that implements the basic stream operations.

So what you need now is to figure out how to open an HTTP connection to your music location and get back a download stream. Exactly how that’s done depends on what language and what Internet framework you’re using, but you should be able to figure it out with a bit of research. Once you’ve got that, just wrap your stream in an SDL_RWops and feed it to SDL.

…except that under some circumstances (I forget exactly which) the SDL code will want to read the entire song into memory all at once instead of playing it continually from the stream. This is obviously designed for local files and won’t work for streaming audio from the Internet. So keep that in mind and if it becomes a problem, you’ll have to look into it and maybe ask some questions here. But first things first, figure out how to get an HTTP stream.

Mason

Hi Mason, thank you for your answer.

In fact, when I was trying to use SDL_RWops, I was trying to do as you say in your message. As it needs a FILE object as first argument, I was trying to feed it with a FILE that was being updated with ‘fread’ function, but with no luck (I mean, I wasn’t able to get the stream). That’s why I was wondering that maybe somebody could help me in getting the stream, because I thought it should be easy to do.

I am using c++ and the internet file I want to stream is just a normal one that you can find in any webpage (I mean http://…/audio.wav).


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

**

Mason Wheeler wrote:

Looks like you’re trying to treat this as one problem, when it’s
actually two. You need to be able to do two separate things, download a
file and play a song from a stream, and then combine them.

The various SDL music-playing functions only know how to play files from
streams. (And a few helper functions to load a local file from disc into a
stream, so they can play from the stream.) But when it comes down to it, a
SDL_RWops is a stream interface, and you can wrap one around any object
from any language that implements the basic stream operations.

So what you need now is to figure out how to open an HTTP connection to
your music location and get back a download stream. Exactly how that’s done
depends on what language and what Internet framework you’re using, but you
should be able to figure it out with a bit of research. Once you’ve got
that, just wrap your stream in an SDL_RWops and feed it to SDL.

…except that under some circumstances (I forget exactly which) the SDL
code will want to read the entire song into memory all at once instead of
playing it continually from the stream. This is obviously designed for
local files and won’t work for streaming audio from the Internet. So keep
that in mind and if it becomes a problem, you’ll have to look into it and
maybe ask some questions here. But first things first, figure out how to
get an HTTP stream.

Mason

Hi Mason, thank you for your answer.

In fact, when I was trying to use SDL_RWops, I was trying to do as you say
in your message. As it needs a FILE object as first argument, I was trying
to feed it with a FILE that was being updated with ‘fread’ function, but
with no luck (I mean, I wasn’t able to get the stream). That’s why I was
wondering that maybe somebody could help me in getting the stream, because
I thought it should be easy to do.

I am using c++ and the internet file I want to stream is just a normal one
that you can find in any webpage (I mean http://…/audio.wav).

This is way beyond the scope of SDL. You need to another library to enable
internet functionality as a file stream. Try looking at cURL for that part.
In general, writing an HTTP file stream library is not a trivial thing to
do manually, and certainly wouldn’t fall into the category of “easy”. It
also would definitely not be “built-in” like it might be in some scripting
languages or Java. C/C++ standard libraries don’t operate at that level.On Wed, May 30, 2012 at 1:07 AM, hmartinez <hector.martinez at sensetrix.com>wrote:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thank you Mason and Patrick for your replies.

I understand what you mean, but it seems still hard for me. I’m trying to search for examples using SDL_AllocRW but there are very few pages with examples.

If I look here (http://sdl.beuc.net/sdl.wiki/SDL_AllocRW), it seems that I have to create all those functions (myseekfunction…), but I have not found the meaning of those functions. Do I have to create a read function where feeding the data? In that case, how to do it with curl (or any other way)?

I have also found this (http://efreedom.com/Question/1-2058141/Reading-SDL-RWops-Std-Istream), but I don’t know (again) how to get the data into the istream.

I don’t know how to approach the problem. Could somebody help me to make up my mind with this issue?

Thank you.

Have a look at http://code.google.com/p/turbu/source/browse/trunk/classes/jedi-sdl/SDL/Pas/sdlstreams.pas?spec=svn224&r=224

It’s a Delphi implementation of wrapping a SDL_RWops around a Delphi stream object.? (And a few other routines, but the part you want is SDLStreamSetup, and the routines it references.)? It’s pretty straightforward, and the concepts involved shouldn’t be too difficult to translate to another language.________________________________
From: hmartinez <hector.martinez at sensetrix.com>
To: sdl at lists.libsdl.org
Sent: Friday, June 1, 2012 3:55 AM
Subject: Re: [SDL] Streaming audio

Thank you Mason and Patrick for your replies.

I understand what you mean, but it seems still hard for me. I’m trying to search for examples using SDL_AllocRW but there are very few pages with examples.

If I look here, it seems that I have to create all those functions (myseekfunction…), but I have not found the meaning of those functions. Do I have to create a read function where feeding the data? In that case, how to do it with curl (or any other way)?

I have also found this, but I don’t know (again) how to get the data into the istream.

I don’t know how to approach the problem. Could somebody help me to make up my mind with this issue?

Thank you.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thank you for the link Mason. This example and the one that I post in the previous message look similar, so it seems it is the way to do it. But I still need to know how to construct the stream that I need to wrap (the TStream in your link). I will continue trying to find how to do it, but if somebody knows how to do it in c++ (using curl or whatever), please let me know.

Mason Wheeler wrote:> Have a look at http://code.google.com/p/turbu/source/browse/trunk/classes/jedi-sdl/SDL/Pas/sdlstreams.pas?spec=svn224&r=224

It’s a Delphi implementation of wrapping a SDL_RWops around a Delphi stream object. (And a few other routines, but the part you want is SDLStreamSetup, and the routines it references.) It’s pretty straightforward, and the concepts involved shouldn’t be too difficult to translate to another language.

From: hmartinez <@hmartinez>
To: sdl at lists.libsdl.org
Sent: Friday, June 1, 2012 3:55 AM
Subject: Re: [SDL] Streaming audio

  Thank you Mason and Patrick for your replies.

I understand what you mean, but it seems still hard for me. I’m trying to search for examples using SDL_AllocRW but there are very few pages with examples.

If I look here (http://sdl.beuc.net/sdl.wiki/SDL_AllocRW), it seems that I have to create all those functions (myseekfunction…), but I have not found the meaning of those functions. Do I have to create a read function where feeding the data? In that case, how to do it with curl (or any other way)?

I have also found this (http://efreedom.com/Question/1-2058141/Reading-SDL-RWops-Std-Istream), but I don’t know (again) how to get the data into the istream.

I don’t know how to approach the problem. Could somebody help me to make up my mind with this issue?

Thank you.


SDL mailing list
SDL at lists.libsdl.org (SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org (http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)