Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 7th, 2007, 1:12 AM   #1
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 368
Rep Power: 0 King is an unknown quantity at this point
Streaming Sound Over a Socket

I am trying to stream sound over a socket. I am using the FMOD SoundSystem libraries to play the music. I am not expecting people to know FMOD, but maybe you guys could still help me out a bit. I can set up FMOD to stream the file when playing it, I just have to figure out how I can send the data through the socket in chucks and have FMOD playing the chunks while its doing the transferring.

I have the file sending through the socket in chunks working:
// receiving end
char buf[1000] = "";
int n = 0;
std:: ofstream outFile("test.mp3", std::ios::binary);
while ((n = recv(socket, buf, sizeof(buf), 0)) > 0)
{
	outFile.write(buf, n);
}
outFile.close();
So I guess I need to get FMOD to play the sound while this is happening. I think the biggest problem is how do I get them both using the same file, because if the file is open while its receiving the data through the socket, then FMOD will not be able to open the file to play the music.

FMOD code to stream a file and play it:
FMOD::System* system = 0;
FMOD_RESULT fres = FMOD::System_Create(&system);
fres = system->init(4, FMOD_INIT_NORMAL, 0);
FMOD::Sound* sound = 0;
fres = system->createStream("test.mp3", FMOD_CREATESTREAM, 0, &sound);
FMOD::Channel* channel = 0;
// there would be code here to set the stream buffer size accordingly.
fres = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);

Any help at all on how to tackle this would be great.
__________________
I am Addicted to Linux!
King is offline   Reply With Quote
Old Apr 7th, 2007, 1:21 PM   #2
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 368
Rep Power: 0 King is an unknown quantity at this point
Does anyone even know if I have to set up the socket a specific way to handle streaming?
__________________
I am Addicted to Linux!
King is offline   Reply With Quote
Old Apr 7th, 2007, 3:14 PM   #3
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
I think you are taking the wrong approach to this... writing the data to a file and having that file stream back to the audio player. You might manage to make it work, but at the cost of processing power, and what happens to streams that keep on going, the data file can not be easily trimmed.

You need to either everload the classes/functions responsible for stream the data from a file to use a socket escriptord and handle reading the data from the socket instead of the file, or you have to find a way to send data buffers into FMOD and write the data directly into the buffer as it is being received. Typically these buffers are cyclical allowing you to easily create a data stream (this is how Direct Sound generally works).

I don't know FMOD very well, so that is really all the help I can give you, and I don't know how well FMOD will handle doing it the right way.
__________________
Clifford Matthew Roche <geek@cliffordroche.com>
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Old Apr 7th, 2007, 5:29 PM   #4
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 368
Rep Power: 0 King is an unknown quantity at this point
Ok thanks for the tips. I think I will just have to research how FMOD works a bit more. I think I am going to leave that for now and finish the rest of the sockets library I am creating (I will probably start a new thread for reviews on it when I get more of it done).
__________________
I am Addicted to Linux!
King is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Java socket Server compile errors.. n3o_X Java 3 Nov 18th, 2007 12:39 AM
.NET Socket Class hbe02 Show Off Your Open Source Projects 1 Oct 7th, 2006 11:00 AM
how to check if the socket is still connected? myName C++ 1 Jun 14th, 2006 6:27 AM
Socket Server hbe02 C++ 19 May 23rd, 2006 10:14 PM
Socket problem Polyphemus_ C++ 3 Feb 28th, 2006 2:01 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:38 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC