CustardToad - 1 day ago

AvieMix

AvieMix browses a Creative NOMAD Jukebox, Creative Zen or Dell jukebox on Windows 11, copies its tracks to the PC
and sends MP3/WAV tracks to the player. It is built on libnjb 2.2.7 and libusb-win32, and supports the 13 players
libnjb handles in their normal (non-MTP) firmware, listed in setup\players.ps1. It has been tested with a Creative
Zen Touch (USB 041E:411B). The project also includes zentest, a command-line tool for the same players.

File What it is
gui\AvieMix\ The AvieMix program (AvieMix.exe, C# WinForms, .NET Framework 4.8): browse the player, copy and send tracks.
gui\native\zennjb.c Small DLL over libnjb with flat structs, so C# can P/Invoke it.
zentest.c Command-line tool: lists device info, tracks, playlists and data files, and copies tracks to the PC. Never changes the player.
check-zen.ps1 Shows which supported player is plugged in and which driver Windows bound to it (or that it has MTP firmware).
build.ps1 Builds libnjb as a static library, build\zentest.exe, build\zennjb.dll and build\gui\AvieMix.exe (MSVC, .NET SDK; x64).
win32\usb.h Shim: libnjb includes <usb.h>, libusb-win32 calls it lusb0_usb.h.
setup\ Driver install/uninstall scripts, the supported-player list (players.ps1) and the README for the setup kit.
driver\aviemix_libusb0.inf libusb-win32 driver INF for all 13 supported players; make-dist.ps1 builds and signs its catalog.
make-dist.ps1 Builds the setup kit dist\AvieMixSetup (+ .zip) for other PCs.
docs\ Bug report and patch for the libnjb last-block download bug.
Zen Touch Test Guide.pdf Step-by-step tests for zentest on the player.
deps\libnjb\ libnjb-2.2.7.tar.gz from SourceForge (MD5 verified) and its extracted, patched source.
deps\libusb-win32\ libusb-win32-bin-1.4.0.2.zip from github.com/mcuee/libusb-win32 (SHA-256 verified), extracted.

One-time setup

  1. Driver. Run Zadig, choose Options → List All Devices, select Creative Zen Touch (USB ID 041E 411B),
    pick libusb-win32 (not WinUSB: libnjb uses the libusb-0.1 API) and click Install Driver.
    check-zen.ps1 should then report Driver: libusb0. Zadig also puts libusb0.dll in System32.
    To undo: Device Manager → the player → Uninstall device, ticking "delete the driver".
    Or skip Zadig: build the setup kit (below) and run its install.cmd, which covers every supported player.
  2. Compilers. In Visual Studio Installer, add the Desktop development with C++ workload
    (MSVC headers and the Windows SDK). AvieMix also needs the .NET SDK.

Build and run

powershell -ExecutionPolicy Bypass -File .\build.ps1
.\build\gui\AvieMix.exe        # the AvieMix program
.\build\zentest.exe            # command line: first 20 tracks
.\build\zentest.exe -n 0 -v    # every track, every tag
.\build\zentest.exe -D 15      # with libnjb USB debug output

# Copy tracks to the PC with zentest (IDs are the first column of the track list)
.\build\zentest.exe -g 1425144 -g 84652 -o D:\ZenBackup
.\build\zentest.exe -g all -o D:\ZenBackup

Copied files are named Artist - Title.mp3 (or .wma/.wav), and a clash with a different track of the same
name gets (track ID) added. A file that is already there with the right size is skipped, so an interrupted
-g all can just be run again. Ctrl+C cancels the current transfer cleanly with the player and deletes the partial
file. Copying runs at roughly 8–10 MB/s, plus a few seconds up front to read the track list.

The original filenames aren't used: the player only reports them as "extended tags", which libnjb warns make
reading the track list much slower.

AvieMix (the program)

build.ps1 builds build\gui\AvieMix.exe when the .NET SDK is installed. It connects on start-up and shows
the player's details, all tracks (sortable, searchable), playlists and data files, and copies selected or listed
tracks to a folder with progress and Cancel. Naming and skip rules are the same as zentest's, so each tool skips
tracks the other already copied.

Send to player… (or dragging MP3/WAV files or folders onto the track list) puts tracks on the player.
AudioFile.cs reads each file's length (MPEG frame headers with Xing/Info/VBRI for VBR; WAV fmt/data chunks)
and tags (ID3v2.2–2.4, ID3v1, WAV LIST INFO; otherwise an "Artist - Title" file name). Only PCM WAV is accepted.
Empty artist/album/genre become <Unknown>, like the player's existing library. Tracks already on the player
(same title, artist and size) are skipped; it checks free space and asks first, shows progress, and Cancel leaves
nothing half-sent. Afterwards it re-reads the player and selects the new tracks. It never deletes or changes
existing tracks (ZenDevice.DeleteTrack exists for tests only).

  • The AvieMix icon (gui\AvieMix\Resources\AvieMix.ico) is the program and window icon; the About box
    (toolbar, far right) shows Resources\aviemixlogo.jpg. Both are embedded in AvieMix.exe, so no extra files ship.
  • gui\native\zennjb.c builds build\zennjb.dll: libnjb flattened into fixed-size structs and simple calls.
  • gui\AvieMix\Native.cs P/Invokes it; ZenDevice.cs wraps it and serialises calls with a lock
    (libnjb isn't thread-safe); TrackNaming.cs ports zentest's file naming; MainForm.cs is the window.
  • MainForm.Designer.cs and AboutForm.Designer.cs are in Visual Studio designer format, so the layouts can be
    edited in the form designer: open gui\AvieMix\AvieMix.csproj in Visual Studio. Build zennjb.dll with
    build.ps1 first.
  • It targets .NET Framework 4.8 (built into Windows 10/11) and x64, so nothing extra needs installing.
  • Only one program can use the player at a time: close AvieMix before running zentest, and vice versa.

Setup kit for other PCs

Other PCs don't need Zadig or Visual Studio: give them dist\AvieMixSetup.zip. Its install.cmd trusts the
kit's signing certificate and installs the driver package with pnputil (one admin prompt); uninstall.cmd
reverses both, and also removes the Zen Touch-only package that earlier kits (and Zadig) installed. Build the kit
after changing the code; no player or Zadig is needed:

powershell -ExecutionPolicy Bypass -File .\build.ps1
powershell -ExecutionPolicy Bypass -File .\make-dist.ps1

make-dist.ps1 builds the driver package itself, the way Zadig does:

  1. It copies driver\aviemix_libusb0.inf and the libusb-win32 1.4.0.2 files (libusb0.sys, libusb0.dll,
    libusb0_x86.dll, all signed by Microsoft), after checking that the INF lists exactly the players in
    setup\players.ps1.
  2. It makes a catalog of their hashes with makecat (Windows SDK).
  3. It signs the catalog with a new self-signed code-signing certificate (CN=AvieMix driver package (libusb-win32),
    valid 20 years), then deletes the certificate's private key, so it can't sign anything else.
  4. It checks every package file is in the catalog, and ships the public certificate as driver\aviemix-driver.cer.

Each build gets its own certificate. The package is x64-only.

Changes to libnjb

All in deps\libnjb\libnjb-2.2.7\src\, marked AvieMix patch:

  • libnjb.h: #define snprintf _snprintf only for compilers older than VS2015 (newer ones reject it with a hard error).
  • libnjb.h: on Windows the u_intN_t types come from <stdint.h>, replacing libnjb's own int8_t/int16_t/...
    typedefs, which clash with <stdint.h> (included by usb_io.c).
  • procedure.c: includes <io.h> under MSVC so the open/read/write/close calls used for track and file
    transfers are properly declared.
  • procedure.c (NJB_Get_Track_fd): asks for exactly the bytes left in the last block (rounded up to even).
    Asking for more made the USB read wait for a zero-length packet the player never sends when that remainder is a
    multiple of 512 smaller than the request, so about 4% of tracks (16 of 390 here, all with sizes that are exact
    multiples of 512) timed out after ~80 s and could not be copied. Write-up and patch: docs\.

zennjb.dll also sets its own C runtime to UTF-8 (setlocale(LC_CTYPE, ".UTF8")) so libnjb's narrow open() and
stat() accept any file name when sending; this needs Windows 10 1803 or later.

The remaining compiler warnings are upstream size/sign conversions and debug-only printf formats; they don't
affect reading from the player.