Skip to content

Commit

Permalink
Add initial support for Broadcast Wave Format (BWF)
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Feb 23, 2022
1 parent db766ab commit 209e5d8
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) | <img src="https://svgshare.com/i/UT8.svg" width="40" alt="AAC logo"> |
| APE | Monkey's Audio | [:link:](https://wikipedia.org/wiki/Monkey's_Audio) | <img src="https://foreverhits.files.wordpress.com/2015/05/ape_audio.jpg" width="40" alt="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) | <img src="https://upload.wikimedia.org/wikipedia/commons/b/bc/DSDlogo.svg" width="80" alt="DSD logo"> |
| DSF | Sony's DSD Stream File | [:link:](https://wikipedia.org/wiki/Direct_Stream_Digital) | <img src="https://upload.wikimedia.org/wikipedia/commons/b/bc/DSDlogo.svg" width="80" alt="DSD logo"> |
| FLAC | Free Lossless Audio Codec | [:link:](https://wikipedia.org/wiki/FLAC) | <img src="https://upload.wikimedia.org/wikipedia/commons/a/a2/FLAC_logo_vector.svg" width="80" alt="FLAC logo"> |
Expand Down
1 change: 1 addition & 0 deletions lib/ParserFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export class ParserFactory {
return 'aiff';

case '.wav':
case '.bwf': // Broadcast Wave Format
return 'riff';

case '.wv':
Expand Down
40 changes: 40 additions & 0 deletions lib/wav/BwfChunk.ts
Original file line number Diff line number Diff line change
@@ -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<IBroadcastAudioExtensionChunk> = {
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)
};
}
};
14 changes: 14 additions & 0 deletions lib/wav/WaveParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"chapter",
"info",
"parse",
"parser"
"parser",
"bwf"
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down

0 comments on commit 209e5d8

Please sign in to comment.