XNA Creators Club Online
Page 1 of 1 (11 items)
Sort Posts: Previous Next

help playing wav data created dynamically at runtime

Last post 1/9/2009 12:11 AM by Reality Shift. 10 replies.
  • 10/31/2008 10:07 PM

    help playing wav data created dynamically at runtime

    I want to be able to crete a buffer, insert data into that buffer, and have some sort of sound device read and play from that buffer.  I have spent a little time trying to figure this out. 

    I tried using SoundPlayer, but it said I had corrupt header data.  (*I used a stream instead of file location) I suppose I could put data that would simulate a header in first that would indicate a really long file (my song needs to have a length of infinite time, as it has no end, and can change at any time).  But this to me seems like a really nasty way of doing things.  And I'm not exactly sure it would even work.

    I tried adding DirectSound as a reference, but I had a problem with the function:
        SetCooperativeLevel(); 
    The first parameter needs to be a windows form or Control.  How would I make this work for a 360 game?
    Also, someone recommended not using Managed assemblies in XNA.  Could you confirm or deny this?

    I have noticed that others have complained a little about not having direct access to sounds like this, but I didn't see any solutions for it.

    I couldn't find the source for SoundPlayer.cs on my computer (I thought I could just kind of work backwards). 

    I just need something like DirectSound in XNA; does such a thing exist?  If not, could anyone tell me how to play a sound from a buffer and have it work on the 360?  Thank you!
    Mark Baker
  • 11/1/2008 3:32 AM In reply to

    Re: help playing wav data created dynamically at runtime

    You're not going to be able to play a song of infinite length using XNA GS. The capability isn't there to get at the raw audio data. You can play a wave or mp3 file very easily though. :)

    Song song = Content.Load<Song>("somemp3"); 
    MediaPlayer.Play(song); 
     

    Jim Perry - Microsoft XNA MVP
    If people spent a minute searching the forums and reading the FAQs before posting I'd be out of a job.
      Got some XNA Game Studio/XNA Framework development info to share with the community? Put it on the XNA Wiki.
        Please mark posts as Answers or Good Feedback when appropriate.
  • 11/1/2008 2:59 PM In reply to

    Re: help playing wav data created dynamically at runtime

    Well then, here's my dilemma...  I'm trying to make an emulator, where the song data is determined at runtime litterally moments before it is played.  Does anyone have any ideas how I might accomplish this using XNA?  There has to be some sort of work-around.  It doesn't necessarily need to BE XNA, it just to compile in XNA and run on the 360.
    Mark Baker
  • 11/1/2008 3:29 PM In reply to

    Re: help playing wav data created dynamically at runtime

    XNA has been out in this form for 2 years now and nobody has found a way to do any kind ofraw sounds like you want.
    There was one guy who claimed to have done it by reverse engineering the XACT wavebank file format and then he created several very short wavebanks and set them up in a circular buffer so they played right after each other. Then he simply wrote to them one after the other.
    However, when asked for a sample we never heard from him again.
    There may be some new way to do something similar with the new Media APIs but if there is then its non trivial and you will need to work it out for yourself.

    One other thing that you may consider, we've seen several emulators ported to XNA in the past which ran fine on Windows but very slow on the 360... the architecture of them doesn't seem to lend itself well to the JIT compiler on the CF.
    Play Kissy Poo - a game for 4 year olds on Xbox and windows
    The ZBuffer
    News and information for XNA
      Follow The Zman on twitter, Email me
        Please read the forum FAQs - Bug/Feature reporting
          Don't forget to mark good answers and good playtest feedback when you see it!!!
  • 11/1/2008 4:12 PM In reply to

    Re: help playing wav data created dynamically at runtime

    Ok, I understand how this concept would work using wav files and C# on my computer, but you're saying that in order to do it on the 360, I have to "hack" the XACT file format, and write to them instead of .wav files?  Assuming the file format could be figured out, is overwriting them trivial, or is that similarly hard?
    Mark Baker
  • 11/1/2008 4:33 PM In reply to

    Re: help playing wav data created dynamically at runtime

    I have not seen if the .xwb file format is documented anywhere but this one guy claimed to have done it... writing over a file on the 360 shouldn't be an issue you just have to make sure they are not being read from. 

    Here is the post http://forums.xna.com/forums/p/4076/27858.aspx#27858 - but like I said nobody ever saw the game/sample or the poster again...
    Play Kissy Poo - a game for 4 year olds on Xbox and windows
    The ZBuffer
    News and information for XNA
      Follow The Zman on twitter, Email me
        Please read the forum FAQs - Bug/Feature reporting
          Don't forget to mark good answers and good playtest feedback when you see it!!!
  • 11/6/2008 9:39 PM In reply to

    Re: help playing wav data created dynamically at runtime

    I am trying to make a self-sustaining class out of this, so it runs on its own thread.  All it would need is to have raw sound data input into a buffer.  I don't think my problem is with the file format anymore.  How do I play the files one-RIGHT-AFTER-the-other?  I can get close using timers and such, but it is always succeptable to playing just a little bit soon or late.  It is even worse when the main thread has a lot of activity.  The only way I can think of to get around this, is to have overlapping data in the files, and if my event is early then start playing at the beginning of the file, if it is on time, start at the beginning of new data, and if it is late, start somewhere later in the file.  The new SoundEffect api has this capability doesn't it?  But that kind of moves me away from doing this in XACT.  This whole method should also apply to the SoundEffect API as well right; just doing it with wavs instead of xwb's?  Otherwise is there anyway of telling exactly when a sound (SoundEffect or .xwb) has finished playing.  Is there a way to "PlayList" or something, and I can just add it back in when it finishes playing?  Anyone have any other thoughts or suggestions on how to synchronize the sounds so they play one right after the other (flawlessly)?  Thanks.
    Mark Baker
  • 11/7/2008 2:23 AM In reply to

    Re: help playing wav data created dynamically at runtime

    I'm not sure I understand your scenario. Can you explain what you're trying to achieve? There's currently no way to play game generated audio using the SoundEffect API. To get ordered playback of sound effects you can poll for the sound effect instance state and switch when the state changes?
    Ashu Tatake
    XNA Framework Developer
  • 11/7/2008 7:52 AM In reply to

    Re: help playing wav data created dynamically at runtime

    I was hoping that one of these API's would have some sort of Queue, so that one plays "INSTANTLY" right after the other.  That would solve my little problem of syncing my dynamically generated music.  Polling the SoundEffect instance could possibly have a gap in between songs (as far as I know).  I was also playing around with loading Song objects and playing them with MediaPlayer.  Is there any way that I can input Songs into the MediaPlayer Queue?  Unless I missed something it seems like the only way this ever has more than one song in it is maybe when music is already playing on a zune.  Also, it probably is a little off topic, but can you load the "Zune Library" from a windows game, or just the "windows media player library"; the only source I get is Windows media player...  Is there a way around this?
    Mark Baker
  • 1/8/2009 7:04 PM In reply to

    Re: help playing wav data created dynamically at runtime

    I raised a request for direct sound buffer access back in April 2007 (!) and it's very disappointing that nothing has been done. There are a number of potential benefits, from dynamic sound generation (I was also writing an emulator) to custom realtime effects and enabling playback of alternative audio formats. I sincerely hope this is added to a future version.

    In the interim, you can show that you agree about its importance by voting for it on the MS Connect site where I raised the initial request:

    https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=273398&SiteID=226

    If there are any MS devs reading, is there a reason why this feature has not been added? It would seem to be a great solution to many of the requests on this forum.
  • 1/9/2009 12:11 AM In reply to

    Re: help playing wav data created dynamically at runtime

    Microsoft has said they will be publishing a roadmap in the near future.  Hopefully this will be on it.  It's possible this was already in development or delayed due to the audio api being in flux (XAudio2/3).  Would have been nice if they at least allowed for dynamic creation of SoundEffects if not real time sound buffer manipulation.  :-(
    Dan Melchione | If you ship a good game there will be cake!
Page 1 of 1 (11 items) Previous Next