An .aup3 file is an ordinary SQLite 3
database. These facts come from Audacity’s source code (version 3.7.1, with the
current development line, Audacity 4, which adds a table and a field type), which is
the format’s only definition. There is no compression anywhere in the file: the
project document is binary XML in plain blobs, and the audio is stored as it is
held in memory. The file explorer on this site reads every table and shows the document,
the tracks and a waveform for each; it finds the file by its application ID, whatever
the file is called.
Audacity 4 development builds save .aup4 files with this same container
(same application_id, the same four tables, a user_version
of 4.0.0.1); Audacity’s own test file empty.aup4 is the one real project
file used to check this reference, and is dissected below.
Identifying the file
The file starts with SQLite’s 16-byte string SQLite format 3\0. Two header
fields mark it as Audacity’s. Both are big-endian, as every SQLite header field is.
| Offset | Size | Field | Value |
|---|---|---|---|
| 60 | 4 | user_version | The project format version, packed. See below. |
| 68 | 4 | application_id | 41 55 44 59, the characters AUDY |
Audacity checks both when opening a file. A different application_id gives
the error “This is not an Audacity project file”, and a user_version newer
than the running Audacity’s own version is refused.
The format version
user_version holds four numbers, one per byte:
| Bits | Field | Meaning |
|---|---|---|
| 31 to 24 | Major | Audacity major version |
| 23 to 16 | Minor | Audacity minor version |
| 15 to 8 | Revision | Revision |
| 7 to 0 | ModLevel | Modification level |
So 03 07 00 00 is format 3.7.0.0. Audacity 3 writes the base version of its
release, major.minor.0.0, as the most compatible form. The development line writes
major.minor.0.1 (ProjectSchemaVersion = version, release, 0, 1: the
“schema revision 1” that added project_history), and
its test file has 04 00 00 01, 4.0.0.1. When Audacity opens a project whose
version is lower than its own, it creates the tables it adds
(CREATE TABLE IF NOT EXISTS project_history) and writes its own
user_version; the project’s user_version is written again
at each save. Comparison is field by field, major first.
A second version is inside the document: the version attribute of the
project element, the XML format (1.3.0 in Audacity 3, and
still in Audacity 4’s test file, 2.0.0 in the current source). Audacity
refuses a document whose version is higher than its own, comparing
major, minor and revision as (major × 100 + minor) × 100 + revision.
Tables
A project has three tables, created on first use with
CREATE TABLE IF NOT EXISTS.
project
The last saved state of the project. It has one row, with id 1.
| Column | Type | Meaning |
|---|---|---|
id | INTEGER PRIMARY KEY | Always 1 |
dict | BLOB | The name dictionary of the binary XML |
doc | BLOB | The fields of the project document |
autosave
The same three columns. When a row with id 1 exists, it holds the
unsaved current state, and Audacity loads it to recover from a crash. It is deleted
when the project is saved cleanly.
sampleblocks
One row per block of audio. See sample blocks.
| Column | Type |
|---|---|
blockid | INTEGER PRIMARY KEY AUTOINCREMENT |
sampleformat | integer |
summin, summax, sumrms | REAL |
summary256, summary64k, samples | BLOB |
project_history
Added after Audacity 3.7.1 (schema revision 1; absent from files written by 3.x).
Each save of the project row also copies its document here, so a
damaged current document can be rolled back. Audacity keeps the last 10 and deletes
the older rows.
| Column | Type | Meaning |
|---|---|---|
generation | INTEGER PRIMARY KEY AUTOINCREMENT | Counts the saves; the highest is the newest |
saved_at | INTEGER | Seconds since 1 January 1970 (strftime('%s','now')) |
dict, doc | BLOB | As in project |
sqlite_sequence
AUTOINCREMENT makes SQLite keep its own table sqlite_sequence(name, seq)
with the highest blockid (and generation) ever used. It
appears in the schema once a row has been added (Audacity’s test file has it, empty).
A new block always gets a number higher than any earlier one, even after rows are deleted.
On loading, Audacity deletes any sampleblocks row not referred to by the
document it has read. When any are deleted, the project is treated as recovered.
Which document is read: Audacity looks for the row id = 1 in
autosave first, and loads that one when it exists (marking the project
recovered and modified); otherwise it reads project row 1. When
project has no rows and there is no autosave, the file is an unsaved
temporary project with no document. A project is temporary when project
does not hold exactly one row. Rows with another id are never read.
A real file, byte by byte
Audacity’s own empty.aup4 test file (24,576 bytes, six 4,096-byte pages)
starts like this. The SQLite header is the family’s usual one; the project fields are
marked.
00000000 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 "SQLite format 3\0"
00000010 10 00 02 02 00 40 20 20 00 00 00 08 00 00 00 06 page size 4096, WAL (2, 2), reserved 0,
change counter 8, 6 pages
00000030 00 00 00 00 00 00 00 00 00 00 00 01 04 00 00 01 text encoding 1 (UTF-8),
user_version 04 00 00 01 = 4.0.0.1
00000040 00 00 00 00 41 55 44 59 00 00 00 00 00 00 00 00 no incremental vacuum,
application_id "AUDY"
Its schema has project (root page 2, one row), autosave (3),
sampleblocks (4), sqlite_sequence (5) and
project_history (6), each a one-page table b-tree. The project row has a
517-byte dict and a 973-byte doc, written with 4-byte
characters, and decodes to the empty project in
the binary XML page’s example.
Reading the file without Audacity
- Check the 16-byte string, then
application_idat 68 =AUDYand readuser_versionat 60. - Read the
sqlite_schemarows (page 1) for the root pages ofproject,autosave,sampleblocksandproject_history, and the column order of each. - Walk the table b-tree of each (leaf pages flag 13, interior pages flag 5). A
dict,docorsamplesblob over the local limit continues on overflow pages (4 bytes of next page number, then data); a row’s payload stays on its b-tree page only up to the page size minus 35 bytes, so a sample block (about 1 MiB) always has a chain, and a project document does once it passes a page. The empty project’s rows fit on their pages. Column values that SQLite stores asINTEGER PRIMARY KEY(id,blockid) are the row’s rowid and read as NULL in the record. - Join
dictanddocand decode the binary XML. - For each
waveblock, find thesampleblocksrow and read its samples.
If the project is open in Audacity, the newest rows may be only in the
.aup3-wal file beside it (a write-ahead
log), not yet in the main file; close the project (which checkpoints) before
copying it, or copy both files.
Database settings
Audacity sets the page size to 65,536 bytes, with a VACUUM when the
database has data, and it opens its connections in one of two configurations. Any
SQLite page size is read: Audacity’s own test file uses 4,096-byte pages.
| Setting | Safe configuration | Fast configuration |
|---|---|---|
busy_timeout | 5000 | 5000 |
locking_mode | SHARED | SHARED |
synchronous | NORMAL | OFF |
journal_mode | WAL | OFF |
wal_autocheckpoint | 0 | not set |
While a project is open, SQLite keeps a .aup3-wal file beside it. Audacity’s
source also lists a -shm suffix, but only builds without its
NO_SHM setting use one, and that setting is on everywhere except Windows.
Copying a project needs those files too until it has been closed.