Home » Community » Forums » .NET » Simple C# Sound
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Simple C# Sound
Post New Topic  Post Reply 
I'm creating a CHIP-8 emulator (I'm hoping this will make an NES emulator easier in the future) and sound-wise, I simply need to emit a single pitch tone when the sound timer is greater than zero.

I don't want to deal with DirectX for something this simple, especially since I'm using GDI+ for graphics, so I wouldn't be using any other components of DirectX. The problem is, I can't find a way to emit a simple tone out the speaker.

I know about Console.Beep, but for one thing, it comes out the motherboard speaker which isn't what I want and second it pauses the program while it plays the sound which may mess with the framerates a bit.

Is there a way to emit a tone using only the .NET Framework or will I need to use some sort of other library?

 User Rating: 1076   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I used System.Media.SystemSounds.Beep.Play, which is probably just a wrapper for the Win32 PlaySound function.

 User Rating: 1572   |  Rate This User  Send Private MessageView ProfileView JournalView GD Showcase Entries Report this Post to a Moderator | Link

That's not quite what I'm looking for. That plays that Windows beep sound with an empty space between. I need a constant stream of sound for as long as the timer is going. Basically, I want a Console.Beep type thing only coming out of the speakers instead. Thanks though!

 User Rating: 1076   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

If you're willing to Pinvoke your way through it, waveOutWrite might be adequate although i've never used it.

 User Rating: 1207   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I found quite a few examples of doing this in C# on the web. Just use "C# tone generator" as your search terms.

 User Rating: 1200   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I used MIDI for my CHIP-8 emulator - this is probably the easiest way for simple tones (there's a basic MIDI API wrapper in the source).

For my Master System emulator, I'm using the Windows waveOut API, using the wrapper by Ianier Munoz.

.................................................................................................................................................................
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]


 User Rating: 1962   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

try System.Console.Beep(int frequency, int duration)



"aut viam inveniam aut faciam"---[My Site]---[Some Research and Development]---[3H-GDC]---[An Art Gallery]

 User Rating: 1567   |  Rate This User  Send Private MessageView ProfileView JournalView GD Showcase Entries Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: