Created
February 13, 2013 13:07
-
-
Save KenjiTakahashi/4944472 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import wave | |
import struct | |
def rip(): | |
from ctypes import CDLL,POINTER,c_short | |
cdio=CDLL('libcdio.so') | |
paranoia=CDLL('libcdio_paranoia.so') | |
h=cdio.cdio_open('/dev/cdrom',13) | |
d=paranoia.cdio_cddap_identify_cdio(h,1,None) | |
paranoia.cdio_cddap_open(d) | |
s=paranoia.cdio_paranoia_init(d) | |
for i in range(1,2): | |
firstS=paranoia.cdio_cddap_track_firstsector(d,i) | |
lastS=paranoia.cdio_cddap_track_lastsector(d,i) | |
sectors=paranoia.cdio_cddap_disc_lastsector(d) | |
paranoia.cdio_paranoia_read.restype=POINTER(c_short) | |
f=wave.open('./file'+str(i)+'.wav','wb') | |
f.setparams((2, 2, 44100, 0, 'NONE', 'not compressed')) | |
data=[] | |
for i in range(firstS,lastS+1): | |
r=paranoia.cdio_paranoia_read(s,None) | |
for i in range(1176): | |
value=struct.pack('h',r[i]) | |
data.append(value) | |
f.writeframes(''.join(data)) | |
f.close() | |
paranoia.cdio_cddap_close_no_free_cdio(d) | |
cdio.cdio_destroy(h) | |
def read(): | |
f=wave.open('./lol.wav','rb') | |
numFrames=f.getnframes() | |
numChannels=f.getnchannels() | |
width=f.getsampwidth() | |
raw_data=f.readframes(numFrames) | |
samples=numFrames*numChannels | |
f.close() | |
if width==1: | |
fmt='%iB'%samples | |
elif width==2: | |
fmt='%ih'%samples | |
int_data=struct.unpack(fmt,raw_data) | |
for i in int_data: | |
print i | |
"""ff=wave.open('./rotfl.wav','wb') | |
ff.setparams((2,2,44100,0,'NONE','not compressed')) | |
data=[] | |
for i in int_data: | |
packed=struct.pack('h',i) | |
data.append(packed) | |
ff.writeframes(''.join(data)) | |
ff.close()""" | |
if __name__=='__main__': | |
rip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment