GSM(3) Library Functions Manual GSM(3)

# [NAME](#NAME)

gsm\_create, gsm\_destroy, gsm\_encode, gsm\_decode — GSM 06.10 lossy sound compression

# [SYNOPSIS](#SYNOPSIS)

#include "gsm.h"

gsm gsm\_create();

void gsm\_encode(handle, src, dst)  
gsm handle;  
gsm\_signal src\[160];  
gsm\_frame dst;

int gsm\_decode(handle, src, dst)  
gsm handle;  
gsm\_frame src;  
gsm\_signal dst\[160];

void gsm\_destroy(handle)  
gsm handle;

# [DESCRIPTION](#DESCRIPTION)

Gsm is an implementation of the final draft GSM 06.10 standard for full-rate speech transcoding.

gsm\_create() initializes a gsm pass and returns a 'gsm' object which can be used as a handle in subsequent calls to gsm\_decode(), gsm\_encode() or gsm\_destroy().

gsm\_encode() encodes an array of 160 13-bit samples (given as gsm\_signal's, signed integral values of at least 16 bits) into a gsm\_frame of 33 bytes. (gsm\_frame is a type defined as an array of 33 gsm\_bytes in gsm.h.)

gsm\_decode() decodes a gsm\_frame into an array of 160 13-bit samples (given as gsm\_signals), which sound rather like what you handed to gsm\_encode() on the other side of the wire.

gsm\_destroy() finishes a gsm pass and frees all storage associated with it.

## [Sample format](#Sample_format)

The following scaling is assumed for input to the algorithm:

```


   0  1                             11 12


   S..v..v..v..v..v..v..v..v..v..v..v..v..*..*..*




Only the top 13 bits are used as a signed input value.
The output of gsm_decode() has the three lower bits set to zero.
```

# [RETURN VALUE](#RETURN_VALUE)

gsm\_create() returns an opaque handle object of type gsm, or 0 on error. gsm\_decode() returns -1 if the passed frame is invalid, else 0.

# [EXAMPLE](#EXAMPLE)

```
#include "gsm.h"
gsm handle;
gsm_frame buf;
gsm_signal sample[160];
int cc, soundfd;
play() {	/* read compressed data from standard input, write to soundfd */
	if (!(handle = gsm_create())) error...
	while (cc = read(0, (char *)buf, sizeof buf)) {
		if (cc != sizeof buf) error...
		if (gsm_decode(handle, buf, sample) < 0) error... 
		if (write(soundfd, sample, sizeof sample) != sizeof sample)
			error...
	}
	gsm_destroy(handle);
}
record() {	/* read from soundfd, write compressed to standard output */
	if (!(handle = gsm_create())) error...
	while (cc = read(soundfd, sample, sizeof sample)) {
		if (cc != sizeof sample) error...
		gsm_encode(handle, sample, buf);
		if (write(1, (char *)buf, sizeof buf) != sizeof sample) 
			error...
	}
	gsm_destroy(handle);
}


```

# [BUGS](#BUGS)

Please direct bug reports to jutta@pobox.com and cabo@tzi.org.

# [SEE ALSO](#SEE_ALSO)

[toast(1)](/man/os/gsm/toast.1), [gsm\_print(3)](/man/os/gsm/gsm_print.3), [gsm\_explode(3)](/man/os/gsm/gsm_explode.3), [gsm\_option(3)](/man/os/gsm/gsm_option.3)

---

Document: gsm(3) from gsm 1.0.24-r1 (Chainguard OS)
Source: https://www.quut.com/gsm/gsm-1.0.24.tar.gz
