decode works but eventually dies with AAXGetEncodedAudio: -24

This commit is contained in:
jan 2016-07-12 10:28:18 -07:00
parent 53a366e526
commit 20eea6848a

View File

@ -23,7 +23,6 @@ def main(in_file, out_file, dll_path=None):
if dll_path is None:
dll_path = 'C:/Program Files (x86)/Audible/Bin/AAXSDKWin.dll'
print(dll_path)
dll = ctypes.CDLL(dll_path)
handle = open_file(dll, in_file)
@ -34,6 +33,8 @@ def main(in_file, out_file, dll_path=None):
seek(*a, 0)
authenticate(*a)
print('c', channels, 's', sample_rate)
enc_buf = ctypes.create_string_buffer(0x400)
dec_buf = ctypes.create_string_buffer(0x400 * 200)
@ -41,6 +42,7 @@ def main(in_file, out_file, dll_path=None):
with wave.open(out_file, 'wb') as wav:
wav.setnchannels(channels)
wav.setframerate(sample_rate)
wav.setsampwidth(2)
while True:
enc_data, enc_len = get_encoded_audio(*a, enc_buf)
@ -51,7 +53,7 @@ def main(in_file, out_file, dll_path=None):
dec_data, dec_len = decode_pcm_frame(*a, enc_buf, enc_len, dec_buf)
length += dec_len
wav.writeframes(dec_buf)
wav.writeframes(bytearray(dec_buf)[:dec_len])
close_file(*a)
@ -80,7 +82,7 @@ def get_audio_channel_count(dll, handle):
if res != 0:
raise Exception('AAXGetAudioChannelCount: {}'.format(res))
return n_channels
return n_channels.value
def get_sample_rate(dll, handle):
@ -90,7 +92,7 @@ def get_sample_rate(dll, handle):
if res != 0:
raise Exception('AAXGetSampleRate: {}'.format(res))
return sample_rate
return sample_rate.value
def seek(dll, handle, position=0):
@ -117,7 +119,7 @@ def get_encoded_audio(dll, handle, buf=None):
if res != 0:
raise Exception('AAXGetEncodedAudio: {}'.format(res))
return buf, data_len
return buf, data_len.value
def decode_pcm_frame(dll, handle, in_buf, in_len, out_buf=None):
@ -125,12 +127,12 @@ def decode_pcm_frame(dll, handle, in_buf, in_len, out_buf=None):
out_buf = ctypes.create_string_buffer(0x400 * 200)
data_len = ctypes.c_uint()
res = dll.AAXDecodedPCMFrame(handle, in_buf, in_len, out_buf, len(out_buf), byref(data_len))
res = dll.AAXDecodePCMFrame(handle, in_buf, in_len, out_buf, len(out_buf), byref(data_len))
if res != 0:
raise Exception('AAXDecodedPCMFrame: {}'.format(res))
return out_buf, data_len
return out_buf, data_len.value
def get_chapter_text(dll, handle, chapter_num, buf=None):
@ -143,7 +145,7 @@ def get_chapter_text(dll, handle, chapter_num, buf=None):
if res != 0:
raise Exception('AAXGetChapterText: {}'.format(res))
return buf, data_len
return buf, data_len.value
def get_metadata(dll, handle, mdn):
@ -159,7 +161,7 @@ def get_metadata(dll, handle, mdn):
if res != 0:
raise Exception('AAXGetChapterText: {}'.format(res))
return buf, data_len
return buf, data_len.value
def seek_to_chapter(dll, handle, chapter):
@ -176,7 +178,7 @@ def get_chapter_count(dll, handle):
if res != 0:
raise Exception('AAXGetChapterCount: {}'.format(res))
return n_chapters
return n_chapters.value
def get_current_chapter(dll, handle):
@ -186,7 +188,7 @@ def get_current_chapter(dll, handle):
if res != 0:
raise Exception('AAXGetCurrentChapter: {}'.format(res))
return chapter
return chapter.value
def get_duration(dll, handle):
@ -196,7 +198,7 @@ def get_duration(dll, handle):
if res != 0:
raise Exception('AAXGetDuration: {}'.format(res))
return duration
return duration.value
def get_playback_position(dll, handle):
@ -206,7 +208,7 @@ def get_playback_position(dll, handle):
if res != 0:
raise Exception('AAXGetPlaybackPosition: {}'.format(res))
return position
return position.value
def get_chapter_start_time(dll, handle, chapter):
@ -216,7 +218,7 @@ def get_chapter_start_time(dll, handle, chapter):
if res != 0:
raise Exception('AAXGetChapterStartTime: {}'.format(res))
return position
return position.value
def get_avg_bitrate(dll, handle):
@ -226,7 +228,7 @@ def get_avg_bitrate(dll, handle):
if res != 0:
raise Exception('AAXGetAvgBitrate: {}'.format(res))
return bitrate
return bitrate.value
def get_max_bitrate(dll, handle):
@ -236,5 +238,5 @@ def get_max_bitrate(dll, handle):
if res != 0:
raise Exception('AAXGetAvgBitrate: {}'.format(res))
return bitrate
return bitrate.value