2

現在、Win 7 64 ビット システムで Libspotify を実装しています。再生以外は問題ないようです。callback からデータを取得しますが、保存されたオーディオに audity を使用しても、異常がいっぱいです。さらに調査するために、win32 サンプル (spshell) を取得し、音楽データをファイルに保存するように変更しました。同じ問題、間違いなくこれらの目盛りが入った音楽です。ここに欠けている単純なものがあると確信していますが、何が問題なのか途方に暮れています。私たちのプロジェクトは、これを解決できるまで停止しているため、どんな助けも素晴らしいでしょう.

保存されたオーディオは、ここで見ることができます http://uploader.crestron.com/download.php?file=8001d80992480280dba365752aeaca81

以下は、ファイルを保存するために行ったコードの変更です (テストのみ)。

static FILE *pFile;
int numBytesToWrite=0;
CRITICAL_SECTION m_cs;

int SP_CALLCONV music_delivery(sp_session *s, const sp_audioformat *fmt, const void *frames, int num_frames)
{
    if ( num_frames == 0 )
        return;
    EnterCriticalSection(&m_cs);
    numBytesToWrite = ( num_frames ) * fmt->channels * sizeof(short);
    if (numBytesToWrite > 0 )
        fwrite(frames, sizeof(short), numBytesToWrite, pFile);
    LeaveCriticalSection(&m_cs);
    return num_frames;
}
static void playtrack_test(void)
{


    sp_error err;
    InitializeCriticalSection(&m_cs);
    pFile = fopen ("C:\\zzzspotify.pcm","wb");
    test_start(&playtrack);
    if((err = sp_session_player_load(g_session, stream_track)) != SP_ERROR_OK) {
        test_report(&playtrack, "Unable to load track: %s",  sp_error_message(err));
        return;
    }

    info_report("Streaming '%s' by '%s' this will take a while", sp_track_name(stream_track),
            sp_artist_name(sp_track_artist(stream_track, 0)));
    sp_session_player_play(g_session, 1);
}

void SP_CALLCONV play_token_lost(sp_session *s)
{
    fclose(pFile);
    DeleteCriticalSection(&m_cs);
    stream_track_end = 2;
    notify_main_thread(g_session);
    info_report("Playtoken lost");
}
static int check_streaming_done(void)
{
    if(stream_track_end == 2)
        test_report(&playtrack, "Playtoken lost");
    else if(stream_track_end == 1)
        test_ok(&playtrack);
    else
        return 0;
    fclose(pFile);
    stream_track_end = 0;
    return 1;
}
4

1 に答える 1

3

これが問題のようです:

fwrite(frames, sizeof(short), numBytesToWrite, pFile);

fwriteドキュメントには、2 番目の引数が「書き込まれる各要素のバイト単位のサイズ」であり、3 番目の引数がこの「要素の数、それぞれのサイズがsizeバイトのサイズ」であると記載されています。

あなたが呼び出している方法は、指定されたバッファの最後から実行されるバイトfrwriteを書き込むように指示します。numBytesToWrite * sizeof(short)実際、クラッシュしないことに驚いています。

fwrite呼び出しを次のように変更することをお勧めします。

fwrite(frames, sizeof(char), numBytesToWrite, pFile);

また:

int numSamplesToWrite = num_frames * fmt->channels;
fwrite(frames, sizeof(short), numSamplesToWrite, pFile);

編集:

あなたの音声を詳細に調べた後、私はこれが事実であると確信しました. 曲は半分の速度で再生されているように見え (つまり、2 倍の量のデータが書き込まれている)、アーティファクトはランダム メモリへのバッファ オーバーランのように見えます。

于 2013-01-30T12:01:45.747 に答える