[FFmpeg-devel] [PATCH] Funcom ISS playback

Michael Niedermayer michaelni
Sat Jan 17 01:26:46 CET 2009


On Fri, Jan 16, 2009 at 10:18:21PM +0100, Stefan Gehrer wrote:
> I reworked Jai Menon's patch from last April to play back Funcom ISS
> Audio files and I think I took care of all the comments made at the
> time.
> To actually play back without hissing artefacts I also had to
> introduce a new variation to the long list of ADPCM codec IDs.
> The samples in http://samples.mplayerhq.hu/game-formats/funcom-iss/
> feature both stereo and mono modes and different packet sizes
> and all four samples play back nicely now.
>
[...]
> +    get_token(pb, token, sizeof(token)); //"IMA_ADPCM_Sound"
> +    get_token(pb, token, sizeof(token)); //packet size
> +    sscanf(token, "%d", &iss->packet_size);
> +    get_token(pb, token, sizeof(token)); //File ID
> +    get_token(pb, token, sizeof(token)); //out size
> +    get_token(pb, token, sizeof(token)); //stereo
> +    sscanf(token, "%d", &stereo);
> +    get_token(pb, token, sizeof(token)); //Unknown1
> +    get_token(pb, token, sizeof(token)); //RateDivisor
> +    sscanf(token, "%d", &rate_divisor);
> +    get_token(pb, token, sizeof(token)); //Unknown2
> +    get_token(pb, token, sizeof(token)); //Version ID
> +    get_token(pb, token, sizeof(token)); //Size
> +    sscanf(token, "%d", &stream_size);
> +    
> +    st = av_new_stream(s, 0);
> +    if (!st)
> +        return AVERROR(ENOMEM);
> +    st->codec->codec_type = CODEC_TYPE_AUDIO;
> +    st->codec->codec_id = CODEC_ID_ADPCM_IMA_ISS;
> +    st->codec->channels = stereo ? 2 : 1;


> +    st->codec->sample_rate = 44100 / rate_divisor;

this could be 0, a negative number or even a 1/0
similarly others should be checked to not be <=0 where this isnt valid


> +    st->codec->bits_per_coded_sample = 4;
> +    st->codec->bit_rate = st->codec->channels * st->codec->sample_rate 
> +                                      * st->codec->bits_per_coded_sample;
> +    st->codec->block_align = iss->packet_size;
> +    av_set_pts_info(st, 32, 1, st->codec->sample_rate);
> +
> +    return 0;
> +}
> +

> +static int iss_read_packet(AVFormatContext *s,
> +                           AVPacket *pkt)
> +{
> +    IssDemuxContext *iss = s->priv_data;
> +    ByteIOContext *pb = s->pb;
> +    int ret = av_get_packet(pb, pkt, iss->packet_size);

as pb is used just once its not too usefull as seperate var.


> +
> +    if(ret < 0)
> +        return ret;
> +
> +    pkt->stream_index = 0;

> +    pkt->pts = iss->sample_count;
> +    iss->sample_count += (ret / s->streams[0]->codec->channels);

cant this be done by url_ftell() ? 
that way it would naturally work with seeking

[...]
> +        if(st) {
> +            c->status[0].predictor  = (int16_t)AV_RL16(src + 0);
> +            c->status[0].step_index = src[2];
[...]
> +        } else {
> +            c->status[0].predictor  = (int16_t)AV_RL16(src + 0);
> +            c->status[0].step_index = src[2];            
> +            src += 4;
> +        }

hmm

> +        while (src < buf + buf_size) {
> +
> +            if (st) {
> +                *samples++ = adpcm_ima_expand_nibble(&c->status[0],
> +                    src[0] >> 4  , 3);
> +                *samples++ = adpcm_ima_expand_nibble(&c->status[1],
> +                    src[0] & 0x0F, 3);
> +            } else {
> +                *samples++ = adpcm_ima_expand_nibble(&c->status[0],
> +                    src[0] & 0x0F  , 3);
> +                *samples++ = adpcm_ima_expand_nibble(&c->status[0],
> +                    src[0] >> 4, 3);
> +            }

are you ure stereo is not R<->L ? would be more consistent i it is


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I know you won't believe me, but the highest form of Human Excellence is
to question oneself and others. -- Socrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090117/22b53670/attachment.pgp>



More information about the ffmpeg-devel mailing list