Skip to content

Commit 2fe9da7

Browse files
committed
Have WSPREncodeToFrequencies return Long array
1 parent 8f47656 commit 2fe9da7

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

AudioCoder/src/main/java/org/operatorfoundation/audiocoder/CJarInterface.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ public class CJarInterface {
1414
* @param power Power level in dBm (0-60)
1515
* @param offset Frequency offset in Hz (added to 1500 Hz base)
1616
* @param lsb LSB mode - inverts symbol order if true
17-
* @return byte array containing 162 frequencies as 64-bit integers (freq * 100)
18-
* Array size: 1,296 bytes (162 symbols × 8 bytes each)
17+
* @return long array containing 162 frequencies (Hz * 100 for 0.01 Hz precision)
1918
*/
20-
public static native byte[] WSPREncodeToFrequencies(String callsign, String locator, int power, int offset, boolean lsb);
19+
public static native long[] WSPREncodeToFrequencies(String callsign, String locator, int power, int offset, boolean lsb);
2120

2221
public static native byte[] WSPREncodeToPCM(String callsign, String locator, int power, int offset, boolean lsb);
2322

AudioCoder/src/main/jni/libloud.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,10 @@ Java_org_operatorfoundation_audiocoder_CJarInterface_WSPREncodeToPCM
9393
* @param j_offset Frequency offset in Hz (added to base 1500 Hz)
9494
* @param lsb_mode LSB mode flag - inverts symbol order if true
9595
*
96-
* @return jbyteArray containing 162 frequencies as 64-bit integers (* 100)
97-
* Total array size: 162 symbols * 8 bytes = 1,296 bytes
98-
* Each frequency is stored as big-endien 64-bit integer with 0.01 Hz precision
96+
* @return jlongArray containing 162 frequencies as 64-bit integers (* 100)
97+
* Each frequency has 0.01 Hz precision
9998
*/
100-
extern "C" JNIEXPORT jbyteArray
99+
extern "C" JNIEXPORT jlongArray
101100
JNICALL
102101
Java_org_operatorfoundation_audiocoder_CJarInterface_WSPREncodeToFrequencies(JNIEnv *env, jclass cls, jstring j_calls, jstring j_local, jint j_powr, jint j_offset, jboolean lsb_mode) {
103102
// Array to hold the 162 WSPR symbols (0-3 values representing frequency shifts)
@@ -125,9 +124,7 @@ Java_org_operatorfoundation_audiocoder_CJarInterface_WSPREncodeToPCM
125124
env->ReleaseStringUTFChars(j_calls, callsign);
126125
env->ReleaseStringUTFChars(j_local, loca);
127126

128-
// Allocate array for frequency data (162 frequencies x 8 bytes each)
129-
const int FREQUENCY_ARRAY_SIZE = WSPR_SYMBOL_COUNT * sizeof(int64_t);
130-
int64_t *frequencies = (int64_t *) malloc(FREQUENCY_ARRAY_SIZE);
127+
int64_t *frequencies = (int64_t *) malloc(WSPR_SYMBOL_COUNT * sizeof(int64_t));
131128

132129
if (frequencies == NULL)
133130
{
@@ -166,25 +163,25 @@ Java_org_operatorfoundation_audiocoder_CJarInterface_WSPREncodeToPCM
166163
}
167164
}
168165

169-
jbyteArray result = env->NewByteArray(FREQUENCY_ARRAY_SIZE);
166+
jlongArray result = env->NewLongArray(WSPR_SYMBOL_COUNT);
170167
if (result == NULL)
171168
{
172169
__android_log_print(ANDROID_LOG_ERROR,
173170
APPNAME,
174-
"Failed to create Java byte array for WSPR encoding.");
171+
"Failed to create Java long array for WSPR encoding.");
175172
free(frequencies);
176173
return NULL;
177174
}
178175

179-
// Copy frequency data to Java byte array
180-
env->SetByteArrayRegion(result, 0, FREQUENCY_ARRAY_SIZE, (jbyte *) frequencies);
176+
// Copy frequency data to Java long array
177+
env->SetLongArrayRegion(result, 0, WSPR_SYMBOL_COUNT, (jlong *) frequencies);
181178

182179
// Don't forget to clean up after yourself!
183180
free(frequencies);
184181

185182
__android_log_print(ANDROID_LOG_INFO, APPNAME,
186-
"WSPR frequency encoding complete: %d frequencies, %d bytes",
187-
WSPR_SYMBOL_COUNT, FREQUENCY_ARRAY_SIZE);
183+
"WSPR frequency encoding complete: %d frequencies",
184+
WSPR_SYMBOL_COUNT);
188185

189186
return result;
190187
}

0 commit comments

Comments
 (0)