Windows Beep() equivalent for Linux

前端 未结 6 781
我在风中等你
我在风中等你 2021-02-09 12:38

I am experimenting with Beep function on Windows:

#include 
...
Beep(frequency, duration);

The computer then beeps with some f

6条回答
  •  忘了有多久
    2021-02-09 13:13

    lets have us some gabba coming from the audio speakers

    #!/usr/bin/ruby
    
    $audio = File.open("/dev/audio", "w+")
    def snd char
        $audio.print char.chr
    end
    
    def evil z
        0.step(100, 4.0 / z) { |i|
            (i / z).to_i.times { snd 0 }
            (i / z).to_i.times { snd 255 }
        }
    end
    
    loop {
        evil 1 
        evil 1
        evil 1
        evil 4
    }
    

    more seriously though:

    //g++ -o pa pa.cpp -lportaudio
    #include 
    #include 
    
    int callback(void*, void* outputBuffer, unsigned long framesPerBuffer, PaTimestamp, void*) {
        float *out = (float*)outputBuffer;
        static float phase;
        for(int i = 0; i < framesPerBuffer; ++i) {
            out[i] = std::sin(phase);
            phase += 0.1f;
        }
        return 0;
    }
    
    int main() {
        Pa_Initialize();
        PaStream* stream;
        Pa_OpenDefaultStream(&stream, 0, 1, paFloat32, 44100, 256, 1, callback, NULL);
        Pa_StartStream(stream);
        Pa_Sleep(4000);
    }
    

提交回复
热议问题