# audio-quarkus-native
**Repository Path**: under0/audio-quarkus-native
## Basic Information
- **Project Name**: audio-quarkus-native
- **Description**: quarkus原生编译使用ffmpeg进行音频处理
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2025-08-28
- **Last Updated**: 2025-09-10
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# audio-quarkus-native
This project uses Quarkus, the Supersonic Subatomic Java Framework.
If you want to learn more about Quarkus, please visit its website: .
## Running the application in dev mode
You can run your application in dev mode that enables live coding using:
```shell script
./mvnw quarkus:dev
```
> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at .
## Packaging and running the application
The application can be packaged using:
```shell script
./mvnw package
```
It produces the `quarkus-run.jar` file in the `target/quarkus-app/` directory.
Be aware that it’s not an _über-jar_ as the dependencies are copied into the `target/quarkus-app/lib/` directory.
The application is now runnable using `java -jar target/quarkus-app/quarkus-run.jar`.
If you want to build an _über-jar_, execute the following command:
```shell script
./mvnw package -Dquarkus.package.jar.type=uber-jar
```
The application, packaged as an _über-jar_, is now runnable using `java -jar target/*-runner.jar`.
## Creating a native executable
You can create a native executable using:
```shell script
./mvnw package -Dnative
```
Or, if you don't have GraalVM installed, you can run the native executable build in a container using:
```shell script
./mvnw package -Dnative -Dquarkus.native.container-build=true
```
You can then execute your native executable with: `./target/audio-quarkus-native-1.0-SNAPSHOT-runner`
If you want to learn more about building native executables, please consult .
## Related Guides
- REST Jackson ([guide](https://quarkus.io/guides/rest#json-serialisation)): Jackson serialization support for Quarkus
REST. This extension is not compatible with the quarkus-resteasy extension, or any of the extensions that depend on it
## Provided Code
### REST
Easily start your REST Web Services
[Related guide section...](https://quarkus.io/guides/getting-started-reactive#reactive-jax-rs-resources)
### 重采样后声音有杂音修复
Root Cause & Fixes:
1. ❌ Incorrect Sample Count Calculation
Problem:
```java
int inputSize = bytesRead / 4; // Wrong: This calculated samples per channel
int outputChannels = 1; // Wrong: Doesn't account for actual channel count
```
✅ Fixed:
```java
int totalSamples = bytesRead / 4; // Total sample pairs for interleaved format
int samplesPerChannel = totalSamples; // Correct for interleaved input
int outputChannels = codecContext.ch_layout().nb_channels(); // Real channel count
```
2. ❌ Wrong Pointer Position/Limit Setup
Problem:
```java
samples_in[i].position(0).limit(inputSize * inputDepth); // Used wrong calculation
```
✅ Fixed:
```java
samples_in[i].position(0).limit(bytesRead); // Direct byte count from audio input
```
3. ❌ Incorrect Input/Output Count Calculation
Problem: Used complex calculations that didn't account for format differences
✅ Fixed:
```java
// Input (Interleaved): Calculate available samples considering channel interleaving
int availableInputBytes = (int)(samples_in[0].limit() - samples_in[0].position());
int inputCount = availableInputBytes / (inputChannels * inputDepth);
// Output (Planar): Each plane contains one channel
int availableOutputBytes = (int)(samples_out[0].limit() - samples_out[0].position());
int outputCount = availableOutputBytes / outputDepth;
```
4. ❌ Wrong Pointer Position Updates
Problem: Used incorrect multipliers for pointer advancement
✅ Fixed:
```java
// Input (Interleaved): Advance by converted samples * all channels
samples_in[i].position(samples_in[i].position() + ret * inputChannels * inputDepth);
// Output (Planar): Each plane advances by converted samples only
samples_out[i].position(samples_out[i].position() + ret * outputDepth);
```
Why These Fixes Solve the Issues:
🔧 Crackling/Buzzing Noise:
Caused by: Incorrect sample boundaries and pointer positions causing data corruption
Fixed by: Proper buffer position management and correct sample calculations
⚡ Fast Playback Speed:
Caused by: Wrong sample rate calculations making the resampler think there was more/less data than actual
Fixed by: Correct sample count calculations that match the actual audio data format
🎯 Enhanced Debugging:
Added comprehensive logging to monitor sample counts, buffer positions, and channel calculations
This will help you verify the resampling is now working correctly
Expected Results:
After these fixes, your resampled PCM files should have:
✅ Normal playback speed (no longer fast)
✅ Clean audio (no crackling or buzzing noise)
✅ Proper channel separation (left/right channels correctly processed)
### 速度变快修复
Root Cause of Double Speed:
The issue was in how we were calculating and handling the sample counts for interleaved stereo input:
❌ Previous (Wrong) Calculation:
```java
int samplesPerChannel = totalSamples; // Treated total samples as per-channel samples
// This made the resampler think there were twice as many samples as actually existed
```
✅ Fixed Calculation:
```java
int samplesPerChannel = totalSamples / 2; // Correct: total samples divided by channel count
// For stereo interleaved: 4608 bytes = 1152 sample pairs = 1152 samples per channel
```
Key Changes Made:
1. Fixed Sample Count Calculation
Interleaved stereo format: Each "frame" contains left+right samples
Total samples = bytes / 4 (2 channels × 2 bytes per sample)
Samples per channel = total samples / 2 (divide by channel count)
2. Corrected Pointer Updates
Input pointer: Advances by inputCount * inputChannels * inputDepth (consumed input)
Output pointer: Advances by ret * outputDepth (produced output)
3. Enhanced Debugging
Added detailed logging to track input→output sample conversion ratios
This will help verify the resampling is working at correct speed
Why This Fixes the Speed Issue:
Before: The resampler was told it had 2304 samples per channel when it actually had 1152
Result: Processed twice as fast → double speed playback
After: The resampler correctly sees 1152 samples per channel
Result: Normal speed processing → correct playback speed
Expected Results:
Now your resampled PCM should have:
✅ Normal playback speed (no longer doubled)
✅ No crackling noise (already fixed)
✅ Proper stereo separation