To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

The primary repository for this project is hosted at https://github.com/Codasign/york-software-bootcamp-audio-day.git .
This repository is a read-only copy which is updated automatically every hour.

Statistics Download as Zip
| Branch: | Revision:

root / 9-dsp-block-by-block.py @ 4:2b996e1d64da

History | View | Annotate | Download (1.23 KB)

1
import numpy as np
2
from scikits.audiolab import wavread
3

    
4
#################################################
5
############ EXTRACT AUDIO FROM FILE ############
6
#################################################
7

    
8
x, fs, enc = wavread("viola.wav")
9

    
10

    
11
#################################################
12
#### CALCULATE RMS OF EACH AUDIO BLOCK ####
13
#################################################
14

    
15
hop_size = 2048                             # set hop size
16
frame_size = 4096                           # set frame size
17
frame = np.zeros(frame_size)                # initialise frame with zeros
18
window = np.hanning(frame_size)             # create window of the same length as the hop size
19

    
20
# create empty numpy array to hold our 
21
rms = np.array([])
22

    
23
# run through signal frame by frame 
24
for n in range(0,x.size-hop_size,hop_size):
25
    
26
    # extract a segment of length hop_size
27
    buffer = x[n:n+hop_size]                               
28
    
29
    # add new segment to frame, shifting back samples of frame
30
    frame = np.append(frame[hop_size:frame_size],buffer)  
31
    
32
    # calculate RMS
33
    rms_val = np.sqrt(np.power(frame,2).mean())
34
    
35
    # add amplitude to our numpy array
36
    rms = np.append(rms,rms_val)
37

    
38
print rms
39
    
40
                                   
41