Using Sound files C# - modifying tempo - c#

Does anyone have any idea how to modify the sound speed and play a sound file faster/slower than the original in C#?
At the moment I am using .wav files, I have searched a lot and found that SoundPlayer and AudioVideoPlayback are the only two options to play sound, but none of them contain any special method to increase or decrease the sound speed with which to play with.
I am building a piano application which lets user modify the tempo, this is the situation I am in at the moment. I hope a few musical programmers can help me! Cheers

A similar question was asked earlier:
C# Audio Library
One of the answers there suggested the following tool which might be helpful to you:
http://naudio.codeplex.com/

What you are looking for is a time-stretch audio library, which changes the playback speed but not the pitch -- with almost no artefacts.
A few excellent timestretch libraries available:
dirac: http://www.dspdimension.com/ (best)
rubberband: http://breakfastquay.com/rubberband/

Related

encoding mp3 or other music files

a bit of background:
this summer, i set myself a programming project,
where i want to make an E-jay clone(a program with simple drag-drop blocks which are little bits of music and beat to make a track)
now i dont really know where to start on the whole encoding music bit.
for example:
how does a sound file work?
how do i transform a piece of a sound file into a universal piece of sound information
how do i create a sound file from scratch
how do i add pieces of sound to a previously newly created sound file
im sorry if i seem like one of those guys that cant use google n stuff. but i have no experience with sound or anything on that part.
programming language: C#
ultimate goal: be able to encode a new mp3 file using small sound files which are inserted on certain points in the file to ultimatly make music
any help is appreciated,
thank you for reading my question.
I think you should check NAudio site - it has lots of examples.
Do some research into the MPEG compression standard, as you'll need to know about decoding as well as encoding. If you are going to be ambitious, maybe look into other audio file types as well.
MP3 Links:
MP3 Format
ISO Draft on the MPEG standard

C# and Audio Generation/Playback

I’m making an audio synthesizer and I’m having issues figuring out what to use for audio playback. I’m using physics and math to calculate the source waveforms and then need to feed that waveform to something which can play it as sound. I need something that can 1) play the waveforms I calculate and 2) play multiple sounds simultaneously (like holding one key down on a piano while pressing other keys). I’ve done a fair bit of research into this and I can’t find something that does both of those things. As far as I know, I have 5 potential options:
DirectSound. It can take a waveform (a short[]) as a parameter and play it as sound, and can play multiple sounds simultaneously. But it won’t work with .NET 4.5.
System.Media.SoundPlayer. It works with .NET 4.5 and has better quality audio than Direct Sound, but it has to play sound from a .wav file and cannot play multiple sounds at once (nor can multiple instances of SoundPlayer). I ‘trick’ SoundPlayer into working by translating my waveform into .wav format in memory and then send SoundPlayer a MemoryStream of the in-memory .wav file. Could I potentially achieve control over the playback by altering the stream? I cannot append bytes to the stream (I tried) but I could potentially make the stream an arbitrary size and just re-write all the bytes in the stream with the next segment of audio data every time the end of the stream is reached.
System.Windows.Controls.MediaElement. I have not experimented with this yet, but from MSDNs documentation I don’t see a way to send it a waveform in memory without saving it to disk first and then reading it; I don’t think I can send it a stream.
System.Windows.Controls.MediaPlayer. I have not experimented with this either, but the documentation says it’s meant to be used as a companion to some kind of animation. I could potentially use this without doing any real (user-perceivable) animation to achieve my desired effect.
An open source solution. I’m hesitant to use an open source solution as I find they are typically poorly documented and not very maintainable, but I am open to ideas if there is one out there that is well documented and can do what I need.
Can anyone offer me any guidance on this or how to create flexible audio playback?
http://naudio.codeplex.com , without a doubt. Mark is a regular here on SO, the product is well alive, there are good code examples.
It works. We built some great stuff with it.

Changing Pitch/Amplitude of a WAVE File C#

What I am trying to do is read the Pitch/Amplitude of one wave file, then increase the pitch of another wave file depending on the Pitch/Amplitude of the first. The second part should be simple enough for me. But what library do I need to use (and what method). It would be great if anyone can help. At the moment I am using the SoundTouch http://code.google.com/p/soundtouchnet/ library to up the pitch.
Any help or tips is appreciated.
Try using DirectSound. This tool allows you to do whatever with wav files. There are plenty of sources to find tutorials too.

Sound chords in C#?

I've tried using Console.Beep() at low millisecond rates two play two frequencies 'at once', but the pause between beeps ruins it. I have tried researching it but I've found nothing, and don't know where to start, aside from DirectSound, which I'm looking in to. All I need is to make a program that plays two or more frequencies simultaneously out of one speaker, in C#.
Thanks.
I suggest you look at DirectSound, which has nice .NET bindings. You can use two (or more) Buffer objects and invoke their Play methods to play them simultaneously.
This tutorial shows how to implement a simple drum machine in C# by synthesising sounds on the fly. Hope it helps.
Try looking at using MIDI. This example should get you started. It uses a MIDI library that several people recommend highly.
Console.Beep() is synchronous and does not return until the sound is finished.
Try Simple DirectMedia Layer (SDL.net).
Here's some very simple sample code that will let you play a WAV or MIDI file. This way you can write your code once then just maintain the wav or mid file if you want to make changes to the sound effect.
Play Any Sound File - C# ( Uses DirectX 9.0 for Managed Code )
If you know the frequencies beforehand you can synthesize them into a wave file (audacity or another similar program) and then play the wave file with the SoundPlayer class.
string path = /*path goes here*/;
player = new SoundPlayer(path);
player.Play();
If you need to synthesize them at runtime you would have to write the file by hand. Here's a SO question that you can reference to build the wave files.

Real time audio playback from mic. c#

I am looking to create an application that will allow me to record from my mic and playback the recording through other pc's. At this point however I would just like it to play back on my own computer so I can get it working.
I have been looking at NAudio for the past few hours and it seems like it may be able to help me achieve this goal.
I am just wondering if anyone else has had any experience with this and if it is at all possible?
Thanks,
Stuart
There is an example project on codeproject doing this:
http://www.codeproject.com/KB/cs/Streaming_wave_audio.aspx
I don't know how low the latency is.
As a codec I'd recommend Speex(at least for speech). It's free, open source and offers low latency and low bandwidth.
Bass Audio Library is another solid option worth looking into.
It is possible to do, but you are unlikely to get low latency with WaveIn/WaveOut (possibly better results with WASAPI). You could use the BufferedWaveProvider (in the latest source code) to store up the audio being recorded from the microphone and supplying the output to soundcard.
NAudio is great as a starting point for audio capture and playback but as Mark pointed out the latency might be an issue.
If you take the next step and want to sent the audio data across the network you will need a codec to compress the data as PCM or WAV are uncompressed and for voice you only need a small part of the bandwidth needed for WAV.
As you are working with C# there is a C# port of Speex available, called NSpeex, which might be worth having a look at..

Categories