emulate class d amp

Is it possible to emulate class d amp. That is have audio file and pulse modulate as is done in class d amp

That would be [u]PWM[/u] (Pulse Width Modulation).

You can do almost anything [u]Nyquist[/u], so that might be worth a try. You’ll probably want to use the highest sample rate that Audacity supports (I don’t know what that is, but it can support 192kHz) and assuming you’re going to play the sound through your soundcard (which is “normal” PCM) or save it as a regular sound file, you’ll probably want to make a low-pass filter in Nyquist too.

The highest sample rate supported by Audacity is 1000000 Hz (1 MHz).
As no sound cards support such a high sample rate you need to use “Tracks menu > Resample”

This code run in the Nyquist Prompt effect (http://manual.audacityteam.org/man/nyquist_prompt.html) is a simple way to create PWM:

;version 4
(if (and (soundp *track*)(= *sound-srate* 1000000))
    (osc-pulse 25000 *track*)
    "Error.\nInput must be a mono track\nwith 1,000,000 Hz sample rate.")

To play the encoded audio requires a low pass filter. This is very easy: just leave the “Project Rate” (lower left corner of the main Audacity window) at 44100, and the track will be resampled back down to 44100 Hz for playback, and the resampling automatically applies a low-pass filter to remove everything above 22050 Hz (half the sample rate).

Note that the sound quality will be very poor, but it demonstrates the principle.

And, thinking a bit more about this… if you low-pass filter digitally, you’ve no longer got PWM, you’re back to PCM. But, that should also “demonstrate the principal”.

Quantize-noise is close, (and doesn’t require the overhead of re-sampling to 1MHz) …