Skip to content

Commit dc0f39f

Browse files
authored
Merge pull request #15 from audiohacking/copilot/fix-mp3-decoding-issue
Fix COVER mode MP3 failure: AUDIO_DIR path mismatch breaks file resolution for dit-vae
2 parents 8fe7ad6 + c2230f2 commit dc0f39f

6 files changed

Lines changed: 20 additions & 57 deletions

File tree

.env.example

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ MODELS_DIR=./models
3939
# ACESTEP_CPP_BRANCH=main
4040

4141
# ── Storage ───────────────────────────────────────────────────────────────────
42-
AUDIO_DIR=./public/audio
42+
# Audio directory for generated songs and uploaded reference tracks.
43+
# Relative paths are resolved from the project root (APP_ROOT).
44+
# This is the single source of truth: LocalStorageProvider (writes),
45+
# Express /audio/ endpoint (serves), and the spawn service (reads) all use it.
46+
AUDIO_DIR=./server/public/audio
4347

4448
# ── Auth ──────────────────────────────────────────────────────────────────────
4549
# Change this to a long random string in any multi-user or network-exposed setup.

backend/README.md

Lines changed: 0 additions & 43 deletions
This file was deleted.

server/src/config/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,11 @@ export const config = {
224224

225225
storage: {
226226
provider: 'local' as const,
227-
// Audio directory must match where LocalStorageProvider writes files and
228-
// where Express serves /audio/ from (server/src/index.ts: '../public/audio').
229-
// Both resolve to <server_root>/public/audio, so we use SERVER_ROOT here.
230-
// AUDIO_DIR env override is still supported (resolved against APP_ROOT).
227+
// Single source of truth for the audio directory.
228+
// LocalStorageProvider, Express (/audio/), and the spawn service all read
229+
// this value so they always point at the same filesystem location.
230+
// Default: <server_root>/public/audio (SERVER_ROOT = server/).
231+
// Override via AUDIO_DIR in .env (relative paths are resolved from APP_ROOT).
231232
audioDir: resolveFromRoot(process.env.AUDIO_DIR || path.join(SERVER_ROOT, 'public', 'audio')),
232233
},
233234

server/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ app.use(cors({
7979

8080
app.use(express.json());
8181

82-
// Serve static audio files
83-
app.use('/audio', express.static(path.join(__dirname, '../public/audio')));
82+
// Serve static audio files from the configured audio directory so that any
83+
// AUDIO_DIR env override is honoured consistently across upload, spawn, and serving.
84+
app.use('/audio', express.static(config.storage.audioDir));
8485

8586
// Audio Editor (AudioMass) - needs relaxed CSP for inline scripts and external images
8687
app.use('/editor', (req, res, next) => {

server/src/services/acestep.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,8 @@ async function runViaSpawn(
640640
const batchSize = Math.min(Math.max(params.batchSize ?? 1, 1), 8);
641641
if (batchSize > 1) ditArgs.push('--batch', String(batchSize));
642642

643-
// Cover and repaint modes both require a source audio file
643+
// Cover and repaint modes both require a source audio file.
644+
// dit-vae reads WAV or MP3 natively (via dr_wav / dr_mp3 in audio.h).
644645
if (params.sourceAudioUrl) {
645646
const srcAudioPath = resolveAudioPath(params.sourceAudioUrl);
646647
ditArgs.push('--src-audio', srcAudioPath);

server/src/services/storage/local.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import { writeFile, unlink, stat, mkdir, copyFile } from 'fs/promises';
22
import path from 'path';
3-
import { fileURLToPath } from 'url';
43
import type { StorageProvider } from './index.js';
5-
6-
const __filename = fileURLToPath(import.meta.url);
7-
const __dirname = path.dirname(__filename);
8-
const AUDIO_DIR = path.join(__dirname, '../../../public/audio');
4+
import { config } from '../../config/index.js';
95

106
export class LocalStorageProvider implements StorageProvider {
117
private audioDir: string;
128

139
constructor() {
14-
this.audioDir = AUDIO_DIR;
10+
// Derive the audio directory from the central config so that the storage
11+
// provider always writes to the same location the spawn service resolves
12+
// paths from (config.storage.audioDir, which honours the AUDIO_DIR env var).
13+
this.audioDir = config.storage.audioDir;
1514
}
1615

1716
async upload(key: string, data: Buffer, _contentType: string): Promise<string> {

0 commit comments

Comments
 (0)