From 209e5d86bf6e1dda7b7976bfa0ed9e39f8ff9985 Mon Sep 17 00:00:00 2001 From: Borewit Date: Sat, 12 Sep 2020 12:02:12 +0200 Subject: [PATCH] Add initial support for Broadcast Wave Format (BWF) --- README.md | 1 + lib/ParserFactory.ts | 1 + lib/wav/BwfChunk.ts | 40 ++++++++++++++++++++++++++++++++++++++++ lib/wav/WaveParser.ts | 14 ++++++++++++++ package.json | 3 ++- 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 lib/wav/BwfChunk.ts diff --git a/README.md b/README.md index 90e9a805b..b6de16587 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Supports any common audio and tagging format. | AAC | ADTS / Advanced Audio Coding | [:link:](https://en.wikipedia.org/wiki/Advanced_Audio_Coding) | AAC logo | | APE | Monkey's Audio | [:link:](https://wikipedia.org/wiki/Monkey's_Audio) | Monkey's Audio logo | | ASF | Advanced Systems Format | [:link:](https://wikipedia.org/wiki/Advanced_Systems_Format) | | +| BWF | Broadcast Wave Format | [:link:](https://en.wikipedia.org/wiki/Broadcast_Wave_Format) | | | DSDIFF | Philips DSDIFF | [:link:](https://wikipedia.org/wiki/Direct_Stream_Digital) | DSD logo | | DSF | Sony's DSD Stream File | [:link:](https://wikipedia.org/wiki/Direct_Stream_Digital) | DSD logo | | FLAC | Free Lossless Audio Codec | [:link:](https://wikipedia.org/wiki/FLAC) | FLAC logo | diff --git a/lib/ParserFactory.ts b/lib/ParserFactory.ts index 8a87e60c8..4d692ac80 100644 --- a/lib/ParserFactory.ts +++ b/lib/ParserFactory.ts @@ -161,6 +161,7 @@ export class ParserFactory { return 'aiff'; case '.wav': + case '.bwf': // Broadcast Wave Format return 'riff'; case '.wv': diff --git a/lib/wav/BwfChunk.ts b/lib/wav/BwfChunk.ts new file mode 100644 index 000000000..c50c4401a --- /dev/null +++ b/lib/wav/BwfChunk.ts @@ -0,0 +1,40 @@ +import { IGetToken } from 'strtok3/lib/core'; +import * as Token from 'token-types'; + +export interface IBroadcastAudioExtensionChunk { + description: string; + originator: string; + originatorReference: string; + originationDate: string; + originationTime: string; + timeReferenceLow: number, + timeReferenceHigh: number, + version: number, + umid: Buffer, +} + +/** + * Broadcast Audio Extension Chunk + * Ref: https://tech.ebu.ch/docs/tech/tech3285.pdf + */ +export const BroadcastAudioExtensionChunk: IGetToken = { + len: 420, + + get: (buf, off) => { + return { + description: new Token.StringType(256, 'ascii').get(buf, off).trim(), + originator: new Token.StringType(32, 'ascii').get(buf, off + 256).trim(), + originatorReference: new Token.StringType(32, 'ascii').get(buf, off + 288).trim(), + originationDate: new Token.StringType(10, 'ascii').get(buf, off + 320).trim(), + originationTime: new Token.StringType(8, 'ascii').get(buf, off + 330).trim(), + timeReferenceLow: Token.UINT32_LE.get(buf, off + 338), + timeReferenceHigh: Token.UINT32_LE.get(buf, off + 342), + version: Token.UINT16_LE.get(buf, off + 346), + umid: new Token.BufferType(64).get(buf, off + 348), + loudnessValue: Token.UINT16_LE.get(buf, off + 412), + maxTruePeakLevel: Token.UINT16_LE.get(buf, off + 414), + maxMomentaryLoudness: Token.UINT16_LE.get(buf, off + 416), + maxShortTermLoudness: Token.UINT16_LE.get(buf, off + 418) + }; + } +}; diff --git a/lib/wav/WaveParser.ts b/lib/wav/WaveParser.ts index 35e46c0ee..16faccbb0 100644 --- a/lib/wav/WaveParser.ts +++ b/lib/wav/WaveParser.ts @@ -8,6 +8,7 @@ import { ID3v2Parser } from '../id3v2/ID3v2Parser'; import * as util from '../common/Util'; import { FourCcToken } from '../common/FourCC'; import { BasicParser } from '../common/BasicParser'; +import { BroadcastAudioExtensionChunk } from '../wav/BwfChunk'; const debug = initDebug('music-metadata:parser:RIFF'); @@ -122,6 +123,19 @@ export class WaveParser extends BasicParser { await this.tokenizer.ignore(header.chunkSize); break; + case 'bext': // Broadcast Audio Extension chunk https://tech.ebu.ch/docs/tech/tech3285.pdf + const bext = await this.tokenizer.readToken(BroadcastAudioExtensionChunk); + Object.keys(bext).forEach(key => { + this.metadata.addTag('exif', 'bext.' + key, bext[key]); + }); + break; + + case '\x00\x00\x00\x00': // padding ?? + debug(`Ignore padding chunk: RIFF/${header.chunkID} of ${header.chunkSize} bytes`); + this.metadata.addWarning('Ignore chunk: RIFF/' + header.chunkID); + await this.tokenizer.ignore(header.chunkSize); + break; + default: debug(`Ignore chunk: RIFF/${header.chunkID} of ${header.chunkSize} bytes`); this.metadata.addWarning('Ignore chunk: RIFF/' + header.chunkID); diff --git a/package.json b/package.json index 6f279b3b5..f55492812 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,8 @@ "chapter", "info", "parse", - "parser" + "parser", + "bwf" ], "main": "lib/index.js", "types": "lib/index.d.ts",