---
name: "play_sample"
section: "3alleg"
platform: "linux"
package: "liballegro-doc"
version: "2:4.2.2-2.2"
release: "Debian 6.0 (Squeeze)"
platforms: ["linux"]
url: "https://new.carta.tech/play_sample"
---

# play\_sample(3alleg)

Plays a sample. Allegro game programming library.

## NAME

play\_sample - Plays a sample. Allegro game programming library.

## SYNOPSIS

**#include \<allegro.h\>**

**int play\_sample(const SAMPLE \*spl, int vol, int pan, int freq, int loop);**

## DESCRIPTION

Triggers a sample at the specified volume, pan position, and frequency.  The parameters \`vol' and \`pan' range from 0 (min/left) to 255 (max/right). Frequency is relative rather than absolute: 1000 represents the frequency that the sample was recorded at, 2000 is twice this, etc. If \`loop' is not zero, the sample will repeat until you call stop\_sample(), and can be manipulated while it is playing by calling adjust\_sample(). Example:

```
   /* Scream from the left speaker, twice the freq. */
   int sound = play_sample(scream, 255, 0, 2000, 0);
```

## RETURN VALUE

Returns the voice number that was allocated for the sample or negative if no voices were available.

## SEE ALSO

[**install\_sound**(3alleg)](/install_sound/3alleg.md), [**load\_sample**(3alleg)](/load_sample/3alleg.md), [**adjust\_sample**(3alleg)](/adjust_sample/3alleg.md), [**stop\_sample**(3alleg)](/stop_sample/3alleg.md), [**exsample**(3alleg)](/exsample/3alleg.md), [**exsprite**(3alleg)](/exsprite/3alleg.md)
