Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avformat/wavdec: support loop_start and loop_end from 'smpl' chunk
@ 2025-08-30 23:27 Spencer Alves via ffmpeg-devel
  2025-09-02 20:02 ` [FFmpeg-devel] " Michael Niedermayer via ffmpeg-devel
  0 siblings, 1 reply; 2+ messages in thread
From: Spencer Alves via ffmpeg-devel @ 2025-08-30 23:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Spencer Alves

The 'smpl' chunk is used for sampling music synthesizers, and includes 
things like the pitch of the sample and how to loop it. This exposes the 
loop points as "loop_start" and "loop_end" metadata, that the brstm, 
mca, and scd demuxers already support.

Tested with file output from "Polyphone" soundfont editor.

Signed-off-by: Spencer Alves <impiaaa@gmail.com>
---
  libavformat/wavdec.c | 22 ++++++++++++++++++++++
  1 file changed, 22 insertions(+)

diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index c65e0a2723..fb3749d64d 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -595,6 +595,28 @@ static int wav_read_header(AVFormatContext *s)
                  }
              }
              break;
+        case MKTAG('s', 'm', 'p', 'l'):
+            if (size >= 36 && got_fmt && st->codecpar->sample_rate > 0) {
+                unsigned sample_loop_count;
+                avio_skip(pb, 28);
+                sample_loop_count = avio_rl32(pb);
+                avio_skip(pb, 4);
+                for (unsigned i = 0; i < sample_loop_count; i++) {
+                    avio_skip(pb, 8);
+                    if (av_dict_set_int(&s->metadata, "loop_start",
+                            av_rescale(avio_rl32(pb), AV_TIME_BASE,
+                                       st->codecpar->sample_rate),
+                            AV_DICT_MULTIKEY) < 0)
+                        return AVERROR(ENOMEM);
+                    avio_skip(pb, 8);
+                    if (av_dict_set_int(&s->metadata, "loop_end",
+                            av_rescale(avio_rl32(pb), AV_TIME_BASE,
+                                       st->codecpar->sample_rate),
+                            AV_DICT_MULTIKEY) < 0)
+                        return AVERROR(ENOMEM);
+                }
+            }
+            break;
          }
           /* seek to next tag unless we know that we'll run into EOF */
-- 
2.48.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [FFmpeg-devel] Re: [PATCH] avformat/wavdec: support loop_start and loop_end from 'smpl' chunk
  2025-08-30 23:27 [FFmpeg-devel] [PATCH] avformat/wavdec: support loop_start and loop_end from 'smpl' chunk Spencer Alves via ffmpeg-devel
@ 2025-09-02 20:02 ` Michael Niedermayer via ffmpeg-devel
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Niedermayer via ffmpeg-devel @ 2025-09-02 20:02 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Michael Niedermayer


[-- Attachment #1.1: Type: text/plain, Size: 2328 bytes --]

On Sat, Aug 30, 2025 at 04:27:25PM -0700, Spencer Alves via ffmpeg-devel wrote:
> The 'smpl' chunk is used for sampling music synthesizers, and includes
> things like the pitch of the sample and how to loop it. This exposes the
> loop points as "loop_start" and "loop_end" metadata, that the brstm, mca,
> and scd demuxers already support.
> 
> Tested with file output from "Polyphone" soundfont editor.
> 
> Signed-off-by: Spencer Alves <impiaaa@gmail.com>
> ---
>  libavformat/wavdec.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
> index c65e0a2723..fb3749d64d 100644
> --- a/libavformat/wavdec.c
> +++ b/libavformat/wavdec.c
> @@ -595,6 +595,28 @@ static int wav_read_header(AVFormatContext *s)
>                  }
>              }
>              break;
> +        case MKTAG('s', 'm', 'p', 'l'):
> +            if (size >= 36 && got_fmt && st->codecpar->sample_rate > 0) {
> +                unsigned sample_loop_count;
> +                avio_skip(pb, 28);
> +                sample_loop_count = avio_rl32(pb);
> +                avio_skip(pb, 4);
> +                for (unsigned i = 0; i < sample_loop_count; i++) {
> +                    avio_skip(pb, 8);
> +                    if (av_dict_set_int(&s->metadata, "loop_start",
> +                            av_rescale(avio_rl32(pb), AV_TIME_BASE,
> +                                       st->codecpar->sample_rate),
> +                            AV_DICT_MULTIKEY) < 0)
> +                        return AVERROR(ENOMEM);
> +                    avio_skip(pb, 8);
> +                    if (av_dict_set_int(&s->metadata, "loop_end",
> +                            av_rescale(avio_rl32(pb), AV_TIME_BASE,
> +                                       st->codecpar->sample_rate),
> +                            AV_DICT_MULTIKEY) < 0)
> +                        return AVERROR(ENOMEM);
> +                }
> +            }
> +            break;
>          }
>           /* seek to next tag unless we know that we'll run into EOF */
> -- 

error: corrupt patch at line 38

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

Opposition brings concord. Out of discord comes the fairest harmony.
-- Heraclitus

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 163 bytes --]

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-09-02 20:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-30 23:27 [FFmpeg-devel] [PATCH] avformat/wavdec: support loop_start and loop_end from 'smpl' chunk Spencer Alves via ffmpeg-devel
2025-09-02 20:02 ` [FFmpeg-devel] " Michael Niedermayer via ffmpeg-devel

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git