コード例 #1
0
            # Create a container for the new chord
            # Find the max value in each chunk and interpolate it
            for i in range(len(indices)):
                if len(indices[i]) >= 3:
                    amp_range = self.amplitudes[time][indices[i][0]:indices[i][len(indices[i])-1]]
                    f_index = np.argmax(amp_range) + indices[i][0]
                    # CONSIDER ADDING QUADRATIC PEAK INTERPOLATION
                    #print self.frequencies[f_index], f_index, indices[i]


            print
        return


# If we are running the script, analize the wav file that was passed in
if __name__ == "__main__":
    if len(sys.argv)>1:
        # STEP 1: Open waveform from argv and get mono audio samples
        wav = waveform.open_wave(sys.argv[1])
        wav.setchannelcount(1)
        samples = np.fromstring(wav.getsamples(), dtype='Int16').tolist()

        # STEP 2: Run STFT on samples
        matrix = STFT_Matrix(samples, c_size=2**10)
        matrix.amplitudes = triangular_smoothing(matrix.amplitudes, 3)
        matrix.smooth_amps_2()
        matrix.blip_filter_2()
        matrix.spectrogram()
    else:
        print __doc__
コード例 #2
0
    start = int(float(_start) * bytespersecond) if _start else 0
    end = int(float(_end) * bytespersecond) if _end else len(samples)
    speed = float(_speed) if _speed else 1
    # Play the song using a pyaudio stream
    p = pyaudio.PyAudio()
    stream = p.open(
        format=p.get_format_from_width(wav.getsamplewidth()),
        channels=wav.getchannelcount(),
        rate=int(wav.getsamplerate() * speed),
        output=True,
    )
    for i in xrange(start, end, 1024):
        stream.write(samples[i : i + 1024])
    stream.write(samples[i:end])  # Write the extra samples
    stream.stop_stream()
    stream.close()
    p.terminate()


if __name__ == "__main__":
    if len(sys.argv) > 1:
        wav = waveform.open_wave(argv[1])
        play(
            wav,
            argv[2] if len(argv) > 2 else None,
            argv[3] if len(argv) > 3 else None,
            argv[4] if len(argv) > 4 else None,
        )
    else:
        print __doc__